Building against MSVC2005 toolset using MSVC2010

Visual studio 2010 has more new features and nicer UI than the 2005 version. I would love to move to the new platform, but unfortunately the project that I am working on uses some non-opensourced  C++ library, which was built agains MSVC2005. When I tried to upgrade the whole project to VS2010, it simply didn’t work.

A good thing is that VS2010 support the so called “native multi-targeting”, which allows you to build your project against an earlier version of the platform toolset. To enable this, you just right click the project in VS2010, and open Property, you will find the following,

v100 means that the project will be built against MSVC2010 toolset, there is one more option in the list, which is v90, the MSVC2008 toolset. It’s good that we find this possibility, but on the other side, we are sad that there is no v80 option, since our project was originally a VS2005 project. I searched for some information on the internet, and find this guy’s blog (http://blogs.msdn.com/b/vcblog/archive/2009/12/08/c-native-multi-targeting.aspx), following his explanation, I navigate the windows explorer to the directory (C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\Platforms\Win32\PlatformToolsets) and you will find this,

I created another folder called v80, which will include the same structure as v90 and v100 do. So in the newly created v80 folder I created two files “Microsoft.Cpp.Win32.v80.props”  and “Microsoft.Cpp.Win32.v80.targets”.

The content of the first file is this,

<Project xmlns=”http://schemas.microsoft.com/developer/msbuild/2003“>

<Import Project=”$(VCTargetsPath)\Platforms\Win32\ PlatformToolsets\v80\ImportBefore\*.props”Condition=”Exists(‘$(VCTargetsPath)\Platforms\Win32\PlatformToolsets\v80\ImportBefore’)” />

<PropertyGroup>

<PlatformToolsetVersion>80</PlatformToolsetVersion>

<VCInstallDir>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VC@ProductDir)</VCInstallDir>

<VCInstallDir

Condition=”‘$(VCInstallDir)’ == ””>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\8.0\Setup\VC@ProductDir)</VCInstallDir>

<VSInstallDir>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Setup\VS@ProductDir)</VSInstallDir>

<VSInstallDir

Condition=”‘$(VSInstallDir)’ == ””>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\8.0\Setup\VS@ProductDir)</VSInstallDir>

<FrameworkDir

Condition=”‘$(UseEnv)’ != ‘true'”>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework@InstallRoot)</FrameworkDir>

<FrameworkDir

Condition=”‘$(FrameworkDir)’ == ””>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework@InstallRoot)</FrameworkDir>

<FrameworkSdkDir

Condition=”‘$(UseEnv)’ != ‘true'”>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\.NETFrameWork\v2.0@InstallationFolder)</FrameworkSdkDir>

<FrameworkSdkDir

Condition=”‘$(FrameworkSdkDir)’ == ””>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\.NETFrameWork\v2.0@InstallationFolder)</FrameworkSdkDir>

<FrameworkSdkDir

Condition=”‘$(FrameworkSdkDir)’ == ””>$(Registry:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\.NETFrameWork\v2.0@InstallationFolder)</FrameworkSdkDir>

<FrameworkVersion

Condition=”‘$(UseEnv)’ != ‘true'”>v2.0.50727</FrameworkVersion>

<Framework35Version

Condition=”‘$(UseEnv)’ != ‘true'”>v3.5</Framework35Version>

<ExecutablePath

Condition=”‘$(ExecutablePath)’ == ””>$(VCInstallDir)bin;$(VCInstallDir)PlatformSDK\bin;$(VCInstallDir)PlatformSDK\common\bin;$(VSInstallDir)Common7\Tools\bin;$(VSInstallDir)Common7\tools;$(VSInstallDir)Common7\ide;$(ProgramFiles)\HTML Help Workshop;$(FrameworkSDKDir)bin;$(FrameworkDir)$(FrameworkVersion);$(VSInstallDir);$(SystemRoot)\SysWow64;$(FxCopDir);$(PATH);</ExecutablePath>

<IncludePath

Condition=”‘$(IncludePath)’ == ””>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(VCInstallDir)PlatformSDK\include;$(VCInstallDir)PlatformSDK\common\include;$(FrameworkSDKDir)include;</IncludePath>

<ReferencePath

Condition=”‘$(ReferencePath)’ == ””>$(FrameworkDir)$(FrameworkVersion);$(VCInstallDir)atlmfc\lib;</ReferencePath>

<LibraryPath

Condition=”‘$(LibraryPath)’ == ””>$(VCInstallDir)lib;$(VCInstallDir)atlmfc\lib;$(VCInstallDir)atlmfc\lib\i386;$(VCInstallDir)PlatformSDK\lib;$(VCInstallDir)PlatformSDK\common\lib;$(FrameworkSDKDir)lib;$(VSInstallDir);$(VSInstallDir)lib;</LibraryPath>

<SourcePath

Condition=”‘$(SourcePath)’ == ””>$(VCInstallDir)atlmfc\src\mfc;$(VCInstallDir)atlmfc\src\atl;$(VCInstallDir)crt\src;</SourcePath>

<ExcludePath

Condition=”‘$(ExcludePath)’ == ””>$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(VCInstallDir)PlatformSDK\include;$(VCInstallDir)PlatformSDK\common\include;$(FrameworkSDKDir)include;$(FrameworkDir)$(FrameworkVersion);$(VCInstallDir)atlmfc\lib;</ExcludePath>

<NativeExecutablePath

Condition=”‘$(NativeExecutablePath)’ == ””>$(ExecutablePath)</NativeExecutablePath>

</PropertyGroup>

<Import Project=”$(VCTargetsPath)\Platforms\Win32\ PlatformToolsets\v80\ImportAfter\*..props”Condition=”Exists(‘$(VCTargetsPath)\Platforms\Win32\ PlatformToolsets\v80\ImportAfter’)” />

</Project>

and in the second file,

<Project ToolsVersion=”4.0″ xmlns=”http://schemas.microsoft.com/developer/msbuild/2003″&gt;
<Import Project=”$(VCTargetsPath)\Platforms\Win32\ImportBefore\*.v80.targets” Condition=”Exists(‘$(VCTargetsPath)\Platforms\Win32\ImportBefore’)” />
<UsingTask TaskName=”VCMessage” AssemblyName=”Microsoft.Build.CppTasks.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” />
<PropertyGroup>
<PlatformPrepareForBuildDependsOn>PlatformToolsetPrepareForBuild;$(PlatformPrepareForBuildDependsOn)</PlatformPrepareForBuildDependsOn>
</PropertyGroup>
<!– *******************************************************************************************
PlatformToolsetPrepareForBuild target
******************************************************************************************* –>
<Target Name=”PlatformToolsetPrepareForBuild” DependsOnTargets=”_DetermineManagedStateFromCL;$(PlatformToolsetPrepareForBuildDependsOn)”>
<!– If the project is targeting any other CLR version than v2.0, v3.0, v3.5, issue a warning –>
<VCMessage Condition=”‘$(ManagedAssembly)’ == ‘true’ and
‘$(TargetFrameworkVersion)’ != ‘v3.5’ and
‘$(TargetFrameworkVersion)’ != ‘v3.0’ and
‘$(TargetFrameworkVersion)’ != ‘v2.0’ and ‘$(DesignTimeBuild)’!=’true’ ”
Code=”MSB8002″ Type=”Warning” Arguments=”$(PlatformToolset);$(TargetFrameworkVersion)”/>
</Target>
<Import Project=”$(VCTargetsPath)\Platforms\Win32\ImportAfter\*.v80.targets” Condition=”Exists(‘$(VCTargetsPath)\Platforms\Win32\ImportAfter’)” />
</Project>

Then I cleaned the original project and rebuild all—- it works. Now I can keep using this  IDE to enjoy its new features. Good:D