2

I have a MSBUILD script (.bat file) which builds a project. I need the MSBuild script that will be executed locally (prior to committing to the repo) to run on a specific version of MSBuild that matches our build management and continuous integration server. The issue is that all the local Developer boxes currently have installed:

C:\Windows\Microsoft.NET\Framework\v3.5

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

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

So on their local box they run my build script:

msbuild MyProject.HelloWorld.proj

The problem is that it builds with whichever MSBuild version is listed highest in their Windows path environment variable.

I can tell which version of MSBuild was used by our build log.

I tried specifying the tools version by modifying the script to pass the Toolsversion parameter:

msbuild /toolsversion:14.0 MyProject.HelloWorld.proj

but to no avail the project was built with MSBuild version 4.0.

I could ask all the developers to modify the order of their environment path variable and place C:\Program Files (x86)\MSBuild\14.0 at the top, which then would cause it to build with MSBuild 14, but I was looking for a less obtrusive manner of accomplishing the task.

Additionally, there are other projects that need to be built with the older version of MSBuild, so depending on the project they may need to move the order of the path variables, which I'm trying to avoid.

5
  • Simply use the full path, as they are the same on the machines. If you do want to use better logic, MSBuild has its own registry keys to assist which organize more version related information.
    – Lex Li
    Feb 1, 2017 at 15:26
  • 1
    None of the msbuild.exe versions belong in the PATH. There is very little you can do to stop the devs from screwing it up to serve their own purposes, or using the wrong Developer Command Prompt, consider providing them if the a .bat file. Feb 1, 2017 at 15:35
  • @LexLi Good idea. Feel free to submit as an answer. I may mark it as the answer depending on other answers I receive. Feb 1, 2017 at 15:35
  • @HansPassant the script is indeed currently a .bat, how does that make the specific aforementioned situation better? Feb 1, 2017 at 15:37
  • 1
    Type the full name of the .exe file you want to run so you don't depend on the PATH. Feb 1, 2017 at 15:44

1 Answer 1

2

Change your `.bat' script to invoke a specific msbuild.exe:

"C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe" MyProject.HelloWorld.proj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.