So, in order to have builds that have consistent results on the build server and on my local machine, I use

/tv

when running

msbuild.exe

(in fact, this is enforced in a

psake

script, which also ensures it uses the corresponding version of

msbuild.exe

).

However I cannot use the

/tv

switch when building with Visual Studio. Instead, Visual Studio 2013 and up will use the .net toolchain that shipped with that version of Visual Studio unless:

The environment variable

MSBUILDLEGACYDEFAULTTOOLSVERSION

is set and...

...all the project files have the ToolsVersion attribute set to the version I want to use.

This is so baroque that I cannot believe anyone is actually doing it. My questions are thus:

Is anyone doing the

MSBUILDLEGACYDEFAULTTOOLSVERSION

thing?

If not, is there another way to make Visual Studio use a specific ToolsVersion short of using the version of Visual Studio that shipped with that ToolsVersion? Something that could be stored in version control (so in a project or some other settings file) would be ideal.

And lastly:

Should I even care? Given that each successive version of the C# compiler should be able to handle previous versions' input, and I can set the target .net framework and C# language level in the project file, is this enough to ensure repeatable builds?

(My prejudice is that I should care, since:

I want builds in the IDE and on the build server to be the same (of course)

I want to be able to use VS2015 (and future versions) because it's a better IDE than previous versions, but I don't want to be obliged to use the new toolchain until I decide to.

Some background: I'm asking this because we recently had a CI build error when one of my colleagues submitted C# 6.0 code that compiled fine with Roslyn on their copy of Visual Studio 2015, but failed in CI because that uses the previous release of the .net toolchain (they'd used an automatic property with no setter, which is fine in Roslyn but not in earlier versions). We will be updating the CI build to Roslyn, but I wanted to see if we could prevent this sort of thing happening in the future.

I solved this by writing a Visual Studio extension that temporarily sets the environment variable MSBUILDDEFAULTTOOLSVERSION for the duration of a build; the value to be used is read from a file .toolsversion in the same directory as the .sln file. The psake script reads the same .toolsversion file and passes the value to the /tv switch.

The code for the extension can be found here: https://github.com/guyboltonking/set-toolsversion-extension. Sadly, I'm not working with C++, or indeed with Visual Studio, at the moment, so I can't provide any support for it (but I can tell you I used it with no issues at all for several months).

Kudos to @efaruk for reminding me about the existence of MSBUILDDEFAULTTOOLSVERSION.

Email codedump link for Is there a simple way to make Visual Studio 2015 use a specific ToolsVersion?