且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Visual Studio 2008 中使用 Visual Studio 2010 C++ 工具?

更新时间:2021-07-22 01:21:35

我有点忘记这个问题,直到今天一个朋友说 C++0x 有多棒.我仍然喜欢 VS2008,比 2010 更喜欢 2010,它首先是缓慢的,所以决定试一试.而且,我仍然无法相信它,但只需最少的黑客攻击,它实际上就可以工作.

I kinda forgot about this question until today a friend was saying how great C++0x was. I'm still in love with VS2008, much more than with 2010 which is above all things slow, so decided to give it a go. And, I still can't believe it, but with a minimum of hacks it actually works.

而且效果很好:在 VS2008 之前,您甚至不会注意到它实际上使用的是 2010 工具集.除非您查看 cl/link 的徽标.或者当然,除非您突然能够使用 lambda.到目前为止,我找不到任何问题.像往常一样编辑等工作,构建工作,调试工作,这就是我所需要的.

And it works great: sitting before VS2008 you don't even notice it's actually using the 2010 toolset. Unless you look at cl/link's logo. Or off course, unless you are suddenly able to use lambdas. I could not find any problems so far whatsoever. Editing etc works like it alwasy did, building works, debugging works, that's all I need.

这是我所做的:

  • 制作一个批处理文件来设置环境以与 Windows SDK 7.1/VS2010 工具集一起使用,但将 devenv 从 VS2008 安装中保留.大部分是从 2010 年的 setenv.cmd 复制的.
  • 现在是脏点:将 msobj100.dll、mspdb100.dll、mspdbcore.dll 和 mspdbsrv.exe 复制到 2010 的 VSINSTALLDIR/bin 目录中(或将它们放在您的 PATH somweher 中).这是必需的,否则 cl.exe 不起作用,也不会调试.
  • 从使用 devenv/useenv
  • 运行批处理文件的同一命令行启动
  • 微笑

这是用于 x64 机器的批处理文件:

This is the used batchfile for an x64 machine:

SET PlatformToolset=Windows7.1SDK
SET ToolsVersion=4.0
SET WindowsSDKVersionOverride=v7.1
SET Path32=%ProgramFiles(x86)%
SET "VCINSTALLDIR=%Path32%\Microsoft Visual Studio 10.0\VC\"
SET "VSINSTALLDIR=%Path32%\Microsoft Visual Studio 10.0\"
SET "VCTools=%VCINSTALLDIR%Bin"
SET "VCTools=%VCTools%;%VCTools%\VCPackages;"
SET "VCLibraries=%VCINSTALLDIR%Lib"
SET "VCIncludes=%VCINSTALLDIR%INCLUDE"
SET Path=%FxTools%;%VSTools%;%VCTools%;%SdkTools%;%Path%
SET OSLibraries=%WindowsSdkDir%Lib
SET OSIncludes=%WindowsSdkDir%INCLUDE;%WindowsSdkDir%INCLUDE\gl
SET "LIB=%VCLibraries%;%OSLibraries%;%FxTools%"
SET "LIBPATH=%FxTools%;%VCLibraries%"
SET "INCLUDE=%VCIncludes%;%OSIncludes%"

EDIT 而不是将批处理文件与/useenv 结合,还有另一种方法可以做同样但更直接的事情:VC++ 目录的设置都保存在文件 %APPDATA%/VisualStudio/9.0/VCComponents 中.dat.因此,如果您使用原始文件并将所有出现的 $(VCINSTALLDIR) 替换为 $(ProgramFiles)\Microsoft Visual Studio 10.0\VC\,它也能正常工作.

EDIT instead of batchfile combined with /useenv, there's another way that does the same but more direct: the settings for VC++ Directories are all saved in the file %APPDATA%/VisualStudio/9.0/VCComponents.dat. So if you take the original one and replace all occurrences of $(VCINSTALLDIR) with $(ProgramFiles)\Microsoft Visual Studio 10.0\VC\ it works as well.