How can I force Visual Studio 2010 to use MSBuild 3.5 instead of the new 4.0 ?
I think you can't change the version of MSBuild used within Visual Studio without a dirty hack.
The version of MSBuild tasks, targets, and tools used by MSBuild is determined by the ToolsVersion attribute in the project file.
Problem : If you change the ToolsVersion manually to 3.5 on the project file, Visual Studio 2010 will automatically upgrade the project file's ToolsVersion to 4.0
The solution is to set your project ToolsVersion to 3.6 (or whatever or 4.0 if you really want to override MSBuild 4.0) and then in the registry to create the following key :
\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.6
MSBuildToolsPath
.NET Framework 3.5 Install Path
(C:\Windows\Microsoft.NET\Framework\v3.5)On machine where ToolsVersion is unknown, the default ToolsVersion will be used.
More information on custom toolset definition.
Why do you want that? Is there anything 3.5 capable but 4.0 not?
If your real concern is that when the code is checked out to a machine that does not have .NET 4 installed, you can use MSBuild 3.5 to build the projects (csproj). You need to create a solution file for MSBuild 3.5 as it does not accept the sln file of VS2010.
When MSBuild comes across ToolsVersion="4.0" it will treat it as ToolsVersion="3.5" and then everything continues to work.
My open source project #SNMP utilizes such tricks so the source code can be built on .NET 4, .NET 3.5 and Mono.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With