0

Below is the error when we run dotnet cli commands such as "dotnet build" or "dotnet run" in the terminal.

error MSB4019: The imported project was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.203\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.

It is something to do with VSTool path of .csproj file but not able to figure out where is the fix. Looking for your inputs. Thanks in Advance.

Aditya
  • 67
  • 1
  • 12
  • Inside root tag insert this: – Augusto Ferbonink May 25 '21 at 00:28
  • MSBuildToolsPath is defined in your registry in somewhere like Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\MSBuild\ToolsVersions\... Also try to open you solution by prompt or power shell promtp by tiping "code .". I tryed here and could build succefully with dotnet build – Augusto Ferbonink May 25 '21 at 00:36
  • note: there is a closed issue (deemed as "not a bug") on [visualstudio](https://developercommunity.visualstudio.com/t/vs-2019-webapplication-projects-fail-to-load/414282) site that relates to this. The "solutions and workarounds" as well as the reaction comments to that closing are pertinent. – Brett Caswell May 25 '21 at 00:46
  • I would also like to raise awareness to msbuild logging as well as the existence of utility tools, like "MSBuild Binary and Structured Log Viewer" (an open source project that I am not affiliated to), to help diagnose these types of issues in the future. (i.e. when projects build in one IDE but have issues in others or versions that support msbuild) – Brett Caswell May 25 '21 at 01:17

1 Answers1

0

The $(VSToolsPath) is like: $(Tool Installation Directory) + "\Microsoft\VisualStudio\v16.0\".

And the "WebApplications\Microsoft.WebApplication.targets" file is from msbuild tool.

You should use msbuild.exe instead of dotnet.exe to do build.

Dylan
  • 504
  • 2
  • 5
  • 9