10
votes

I setup a new computer and installed VS2015. Compiling the project I am currently work on results in some invalid code (ILSpy creates uncompilable sources). It worked fine in VS2013 using ToolsVersion 12.

Log file tells me that ToolsVersion 12 is missing, so I installed this. However whatever I do or set, it ALWAYS compiles using ToolsVersion 14. I can manually call MSBuild.exe shipped with VS2013 (uses ToolsVersion 12) and code is correct. Doing the same with MSBuild.exe shipped with VS2015 (uses ToolsVersion 14) results in the INCORRECT code. So all I need is VS2015 to use ToolSet 12.

MSDN says:

"Starting in Visual Studio 2013, the MSBuild Toolset version is the same as the Visual Studio version number. MSBuild defaults to this Toolset within Visual Studio and on the command line, regardless of the ToolSet version specified in project file. This behavior can be overridden by using the /ToolsVersion flag. For more information, see Overriding ToolsVersion Settings."

Setting such using MSBuild manually works fine, but how do I set this in VS 2015 ?? NONE of the environment variables work, it always uses toolset 14 !

1
You will have to uninstall .NET 4.6 so that the Roslyn based compilers are removed. Otherwise, the C# compiler might continue to give you the same invalid assemblies. But generally speaking, ILSpy does not work well with Roslyn compiled assemblies. So your assemblies might be indeed valid, just ILSpy cannot understand them. You can check ILSpy bug list to learn more about that. - Lex Li
Sorry, your suggestion does not fix the problem ! The issue really is that VS uses MSBuild 14. As I mentioned before if I ran MSBuild from the 12 folder all is fine. I renamed the 14 folder and now VS does not load the projects, so its looking for the 14 folder. The solution is simple IF one would know how to change/set the $(MSBuildToolsVersion) variable. This is obviously set to 14 and the ToolsVersion attribute is not honored anymore (as Microsoft states without giving a working solution for a replacement). I renamed the 14 folder to 12 and that results in other crashes... ARGH ! - user1029883
I'm not sure why this has been downvoted. The question still appears to be "How do I get VS2015 to build with an earlier ToolsVersion?" - Guy Bolton King
VS2015 is very different from previous VS versions, Roslyn was integrated and that had a big impact on the IDE. All of the editor features depend on Roslyn-generated metadata. Earlier toolversions of course don't know beans about Roslyn. If you need to do this only because ILSpy cannot keep up then just use another decompiler. Reflector v9 has good C# v6 support. - Hans Passant

1 Answers

3
votes

I'm leaving this answer here in case it helps anyone else, however it hasn't helped the original poster, as according to @user1029883 it doesn't work when VS2015 is installed with the 12.0 Build Tools (see @alexandrul's comment below) instead of multiple versions of Visual Studio: sorry.


Unfortunately, there doesn't seem to be a straightforward way to do this. There is, however, a fiddly way:

  • Set the environment variable MSBUILDLEGACYDEFAULTTOOLSVERSION
  • Ensure the ToolsVersion attribute in the top-level Project element in all your project files is set to the desired ToolsVersion.

See the Overriding ToolsVersion Settings page on MSDN