How to build .NET Framework ASP.NET app using dotnet

Viewed 855

We have a mixture of ASP.NET Core and .NET Framework ASP.NET apps. We use a mixture of msbuild and dotnet to build the apps.

I'm trying to go all in on dotnet, but the build always throws an error of:

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

Right now I'm just trying with a very simple command of dotnet msbuild foo.sln. No flags or anything being used for now.

I've tried this on multiple ASP.NET (not Core) apps and they all give the same error.

1 Answers

For ASP.NET Web applications, you need to compile using the following code.

C:\'Program Files (x86)'\'Microsoft Visual Studio'\[year]\[edition]\MSBuild\Current\Bin\msbuild.exe [project.csproj] /p:VisualStudioVersion=[version] /p:DeployOnBuild=true /p:PublishProfile=[profileName]

You can run in cmd or PowerShell. Replace tags according to the version of Visual Studio installed on your machine and solution version.

For Example:

C:\'Program Files (x86)'\'Microsoft Visual Studio'\2019\Community\MSBuild\Current\Bin\msbuild.exe HelloWorld.csproj /p:VisualStudioVersion=16.0 /p:DeployOnBuild=true /p:PublishProfile=Release
Related