如何选择应用程序应链接到的VC 2008 DLL的版本? [英] How to select the version of the VC 2008 DLLs the application should be linked to?

查看:128
本文介绍了如何选择应用程序应链接到的VC 2008 DLL的版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2008 SP1 for C ++。编译时,Visual Studio需要选择应该链接哪个版本的CRT和MFC DLL,版本9.0.21022.8(= RTM),9.0.30729.17(= SP1)或9.0.30729.4148(= SP1,具有安全更新) 。我想知道如何选择两个版本中的哪一个将被链接。有人知道吗?



注意:使用私有程序集,因为您需要知道哪些版本的VC 9.0 DLL与.exe一起复制。 / p>

注意 _BIND_TO_CURRENT_VCLIBS_VERSION标志仅确保清单中包含正确的版本。运行时的DLL版本选择显然不是基于清单文件中包含的版本进行的。即使清单文件说应该使用v21022,则.exe使用v30729.DLL。我知道这是因为它使用std :: tr1 :: weakptr,它不在v21022中。

解决方案

_BIND_TO_CURRENT_VCLIBS_VERSION设置清单中的当前版本 - 如果没有,则为RTM版本。
将其设置在清单中是正确的方法。



然而,您看到的是汇编策略文件的效果: - 当安装了包含2008 SP1运行时的VCRedist软件包,它将一个策略文件安装到具有bindingRedirect条目的WinSxS存储中,该条目重定向将RTM运行时加载到SP1运行时的尝试。



因此,在其清单中指定RTM运行时的应用程序将加载SP1运行时,并且指定SP1运行时的应用程序将加载SP1运行时。



如果您实际执行要使用RTM运行时,即使安装了SP1运行时和策略文件,则需要在清单中指定RTM版本,并使用应用程序配置文件。基本上yourappname.exe.config(或yourdllname.dll.2.config如果它的一个隔离感知dll造成悲伤)。
应用程序配置文件可以提供一个bindingRedirect元素,该元素覆盖清单中指定的任何程序集版本或策略文件。



此配置文件将告诉操作系统加载即使安装了SP1运行时也是RTM运行时: -

 <?xml version =1.0encoding =UTF- 8standalone =yes?> 
< configuration>
< windows>
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity type =win32name =Microsoft.VC90.CRTprocessorArchitecture =x86publicKeyToken =1fc8b3b9a1e18e3b/>
< bindingRedirect oldVersion =9.0.30729.1newVersion =9.0.21022.8/>
< / dependentAssembly>
< / assemblyBinding>
< / windows>
< / configuration>

注意:oldVersion被允许为范围: oldVersion =9.0。 30729.1-9.1.0.0



请参阅:应用程序配置文件


I'm using Visual Studio 2008 SP1 for C++. When compiling, Visual Studio needs to choose against which version of the CRT and MFC DLLs the application should be linked, version 9.0.21022.8 (= RTM), 9.0.30729.17 (= SP1) or 9.0.30729.4148 (= SP1 with security update). I'd like to know how you can choose which of both versions will be linked against. Does anyone know?

Note: this is important when using a private assembly, because you need to know which versions of the VC 9.0 DLLs to copy along with the .exe.

Note that the _BIND_TO_CURRENT_VCLIBS_VERSION flag only makes sure that the right version is included in the manifest. The DLL version selection at runtime is apparently not done based upon the version that is included in the manifest file. Even if the manifest file says that v21022 should be used, the .exe uses the v30729 .DLLs. I know this, because it uses std::tr1::weakptr, which is not present in v21022.

解决方案

_BIND_TO_CURRENT_VCLIBS_VERSION sets the current version in the manifest - or the RTM version if not. And setting it in the manifest is the correct way to do this.

What you are seeing however is the effects of an assembly policy file :- When the VCRedist package containing the 2008 SP1 runtime is installed, it installs a policy file into the WinSxS store with a bindingRedirect entry that redirects attempts to load the RTM runtime to the SP1 runtime.

So applications that specify the RTM runtime in their manifest will load the SP1 runtime, and applications that specify the SP1 runtime, will load the SP1 runtime.

If you actually DO want to use the RTM runtime, even when the SP1 runtime and policy files are installed, then you need to specify the RTM version in your manifest, AND make use of an application configuration file. Basically "yourappname.exe.config" ( or "yourdllname.dll.2.config" if its an isolation aware dll causing grief). Application congifuration files can supply a bindingRedirect element that overrides any assembly version specified in the manifest, or policy files.

This config file will tell the OS to load the RTM runtime even if the SP1 runtime is installed :-

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
    <windows>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"/>
                <bindingRedirect oldVersion="9.0.30729.1" newVersion="9.0.21022.8"/>
            </dependentAssembly>
        </assemblyBinding>
    </windows>
</configuration>

Note: oldVersion is allowed to be a range: oldVersion="9.0.30729.1-9.1.0.0"

See: Application Configuration Files documented on MSDN.

这篇关于如何选择应用程序应链接到的VC 2008 DLL的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆