简体   繁体   中英

Correct location of MSBuild.exe to build .net 4.5 application using command line

I have asp.net web api application targeting 4.5 framework.

I am trying to create a docker image for my application. In order to build the application, I can use MSBuild.exe available in C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe or C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe locations.

When I build using C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe location, I get error saying " C:\\MyApp-Api\\MyApp-Api.csproj(985,3) : error MSB4019: The imported project "C:\\Program Files (x86)\\MSBuild\\Microsoft \\VisualStudio\\v11.0\\WebApplications\\Microsoft.WebApplication.targets" was not f ound. Confirm that the path in the declaration is correct, and that th e file exists on disk."

I am able to build my application using C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe location.

Questions:

  1. What is the difference between the MsBuild.Exe available in these two folders?
  2. Ideally I think using C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe location is the right approach as it comes with default location and I think MSBuild in program files comes due to installation of Visual Studio. and on my Build server I will not have visual studio installed.
    1. In order to build the application on container, I need to specify SDK which will allow me to build the application. Which version of SDK, I need to build .net 4.5 application.

I was browsing web with a similar query today and stumbled upon this random link to a Veracode extension which lists nicely the difference.

Visual Studio 2017

The first two paths below that contain Professional differ based on the edition of Visual Studio you have installed. Replace Professional with Enterprise or Community, when appropriate.

Note: the Visual Studio Preview install also changes the path based on Enterprise, Professional, or Community.

  • Standard Visual Studio Paths

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\amd64\\

  • Visual Studio Preview Paths

C:\\Program Files (x86)\\Microsoft Visual Studio\\Preview\\Professional\\MSBuild\\15.0\\Bin

  • MSBuild Tools Paths

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin\\

C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\BuildTools\\MSBuild\\15.0\\Bin\\amd64\\

Visual Studio 2015

C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\ C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\amd64\\

Visual Studio 2013

C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\ C:\\Program Files (x86)\\MSBuild\\12.0\\Bin\\amd64\\

Visual Studio 2012

C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\ C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\


It seems like you have both VS2012 and VS2015 installed. I dont know much about ASP.NET and docker but will try to answer your questions:

  1. I think the difference is explained above. The problem you are experiencing there is explained better in here: The imported project Microsoft.WebApplications.targets was not found Maybe give it a go?
  2. Relying on https://dotnet.microsoft.com/download/visual-studio-sdks and https://docs.microsoft.com/en-us/dotnet/framework/install/guide-for-developers it seems like there is no SDK for .net 4.5 as it is included in VS2012. But any higher version should build your project to 4.5 anyway.
  3. Reading (3) I would use VS2015 msbuild if VS2012 gives you a headache.

If you dont mind me asking - Why not switching to ASP.NET Core ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM