Is it possible to change the msbuild version that is used by Visual Studio 2008 when compiling projects?
I would like to set it to use msbuild 4.0.
The reason behind this is to be able to import the same .targets file used by our VS2012 projects for nuget packages restore. The projects cannot be upgraded to VS10+ because they are Smart Device projects.
I tried manually editing the original targets file but too many features are missing in msbuild 3.5 and I couldn’t work around them.
Update:
The original .targets file is also using the automatic download feature for the nuget.exe file, using a code task that is unsupported in the MSBuild 3.5, so this is something that should be taken into consideration.
When you compile from Visual Studio you’re using devenv instead of msbuild. It would be great to see how devenv calls msbuild (but being VS a non open-source tool, we just can’t). So, I don’t think it is possible to do that. Maybe there’s another approach to do what are you’re trying to do.
MSbuild v3.5 does not support dynamic task creation as MSbuild 4.0, but you can create customized tasks and import them.
First, create a simple class library (I called it DownloadNuget2008.dll) containing the task to download nuget.exe (taken from nuget.targets):
I used to restore my NuGet packages on Visual Studio 2008 with the Exec Task below (edit your csproj/vbproj):
Then you will see on the output:
I understand you wish to use the same .targets file to both VS2012 and VS2008, but (as you said) there are many differences between MSBuild 3.5 and 4.0 so a specific approach is easier to do.