Do you want to compile old Website Projects (csproj / vbproj) file with the new “dotnet build” CLI command?
In case of build failure an error similar to the following one might have been reported:
Sample.Web.csproj(2620,3): error MSB4019: The imported project "C:\Program Files\dotnet\sdk\5.0.301\
Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found.
Confirm that the path in the Import "C:\Program Files\dotnet\sdk\5.0.301\Microsoft\VisualStudio\v16.0\
WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.
Paths might change but the problem is the CLI is not able to properly locate the required .targets files (this can often happen on a build server).
The easy solution:
Add the MSBuild.Microsoft.VisualStudio.Web.targets NuGet package (a newer version can be used if available) to the Website project:
The following line of code will be added to your .csproj file:
The following code is not strictly needed, but if you want you can also find the following lines in your .csproj file:
and change them like this:
You can now compile old Websites .csproj / .vbproj using: dotnet build.