如何分发C运行时(CRT)库

时间:2023-02-11 03:13:39

I'm building an application after converting VC++ 6 workspace on Visual C++ 2008 express. Build in itself goes successfully but real problem I have is with the generated manifests which looks like this:

在Visual c++ 2008 express上转换了vc++ 6工作区之后,我正在构建一个应用程序。构建本身是成功的,但我遇到的真正问题是生成的清单是这样的:

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'>
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level='asInvoker' uiAccess='false' />
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.30729.1' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
  </dependency>
</assembly>

My Question is :

我的问题是:

How can I restrict the manifest to list only ONE version , preferably 9.0.21022.8. so that I can bundle the necessary C-Run time dependencies inside my application ?

如何限制manifest只列出一个版本,最好是9.0.21022.8。这样我就可以在应用程序中绑定必要的c运行时依赖项?

I know the possible root cause to this problem is dependency on some library which uses 9.0.21022.8 and my VC++ Express 2008 might be using 9.0.30729.1. that's why both are listed as dependency.

我知道这个问题可能的根源是依赖于使用9.0.21022.8的库,我的vc++ Express 2008可能使用9.0.30729.1。这就是为什么两者都被列为依赖项。

Note:

I'm following approach b) of http://www.codeproject.com/Tips/211756/How-to-Distribute-C-run-time-CRT-Libraries-with-Yo?display=Print which talks about copying the CRT DLL files and Microsoft.VCXX.CRT.manifest file inside application folder.

我在跟踪b) http://www.codeproject.com/tips/211756 / howto - distribute -run-time- crt - libraries -with- yo?display=Print,表示复制CRT DLL文件和Microsoft.VCXX.CRT。应用程序文件夹中的清单文件。

1 个解决方案

#1


9  

The default for Visual Studio 2008 is to bind to version 9.0.21022.8. This is regardless of whatever version of service pack or hotfix you have installed, since updates to Visual Studio should not necessarily force your application to have to upgrade (as described here).

Visual Studio 2008的默认设置是绑定到9.0.21022.8版本。这与您安装的服务包或热修复的版本无关,因为对Visual Studio的更新不一定会迫使您的应用程序进行升级(如本文所述)。

Other possible versions are 9.0.30729.1 for Service Pack 1 or 9.0.30729.6161 for SP1 with a security update. There are others.

其他可能的版本包括服务包1的9.0.30729.1或SP1的9.0.30729.6161的安全性更新。有别人。

Because of the default behaviour, it is likely that your application is using 9.0.21022.8 and there is a library which has been compiled to use 9.0.30729.1. You can find out what version of each library is dependant on by using the following command line (described here):

由于默认行为,您的应用程序可能正在使用9.0.21022.8,并且有一个库已经编译为使用9.0.30729.1。您可以使用以下命令行(这里描述)来查找每个库的依赖版本:

dumpbin /directives <name>.lib

In order to control the version of the runtime that your application binds to you can define preprocessor symbols in your project settings (must be in the project settings or on the command line) to either bind to the default version (9.0.21022.8 - by not defining them) or binding to the same version as your installed Visual Studio:

为了控制版本的运行时,应用程序可以定义预处理器结合符号在你的项目设置(必须在项目设置或在命令行上)是绑定到默认的版本(9.0.21022.8——不是定义)或绑定相同版本的Visual Studio安装:

_BIND_TO_CURRENT_VCLIBS_VERSION=1

Apparently you can also specify the exact version you want to bind to using the defines from this answer (maybe I should have found that first before typing all this out :).

显然,您还可以指定您想要使用这个答案的定义绑定的确切版本(也许我应该在输入所有这些之前先找到它:)。

If you find it is your application that binds to 9.0.30729.1 and the dependant library is binding to 9.0.21022.8 then you simply need to remove the preprocessor definition.

如果您发现是您的应用程序绑定到9.0.30729.1,并且依赖库绑定到9.0.21022.8,那么您只需删除预处理器定义。

The other difficulty is that when you upgrade Visual Studio, the runtime merge modules in your redistributable folder are also upgraded to those versions. So if you have a setup project that uses those merge modules and you are trying to bind to the default version you would end up installing the new versions of the runtimes.

另一个困难是,当您升级Visual Studio时,可再分配文件夹中的运行时合并模块也会升级到这些版本。所以如果你有一个安装项目使用这些合并模块并且你试图绑定到默认版本你最终会安装运行时的新版本。

Resolving the runtime version would not be a problem if you also distribute the runtime policy merge modules, as the library loader will at runtime look at the policy of your runtime and automatically load the newest version even if you bind to the default version. Even with private assemblies the loader will first look in the WinSxS folder so if the policies are there you will bind to the newest version. So your mixed version numbers in your manifest will both redirect to the newest version.

如果您还分发运行时策略合并模块,那么解析运行时版本就不是问题,因为库加载程序将在运行时查看运行时策略并自动加载最新版本,即使您绑定到默认版本。即使使用私有程序集,加载程序也会首先查看WinSxS文件夹,因此如果有策略,您将绑定到最新的版本。所以您的混合版本号在您的清单将重定向到最新的版本。

Sometimes that is not desired and you can control that to force it to load only the version in the manifest that you specify, which is explained in an answer to this similar SO question.

有时,这是不需要的,您可以控制它只加载您指定的清单中的版本,这在类似SO问题的答案中有解释。

#1


9  

The default for Visual Studio 2008 is to bind to version 9.0.21022.8. This is regardless of whatever version of service pack or hotfix you have installed, since updates to Visual Studio should not necessarily force your application to have to upgrade (as described here).

Visual Studio 2008的默认设置是绑定到9.0.21022.8版本。这与您安装的服务包或热修复的版本无关,因为对Visual Studio的更新不一定会迫使您的应用程序进行升级(如本文所述)。

Other possible versions are 9.0.30729.1 for Service Pack 1 or 9.0.30729.6161 for SP1 with a security update. There are others.

其他可能的版本包括服务包1的9.0.30729.1或SP1的9.0.30729.6161的安全性更新。有别人。

Because of the default behaviour, it is likely that your application is using 9.0.21022.8 and there is a library which has been compiled to use 9.0.30729.1. You can find out what version of each library is dependant on by using the following command line (described here):

由于默认行为,您的应用程序可能正在使用9.0.21022.8,并且有一个库已经编译为使用9.0.30729.1。您可以使用以下命令行(这里描述)来查找每个库的依赖版本:

dumpbin /directives <name>.lib

In order to control the version of the runtime that your application binds to you can define preprocessor symbols in your project settings (must be in the project settings or on the command line) to either bind to the default version (9.0.21022.8 - by not defining them) or binding to the same version as your installed Visual Studio:

为了控制版本的运行时,应用程序可以定义预处理器结合符号在你的项目设置(必须在项目设置或在命令行上)是绑定到默认的版本(9.0.21022.8——不是定义)或绑定相同版本的Visual Studio安装:

_BIND_TO_CURRENT_VCLIBS_VERSION=1

Apparently you can also specify the exact version you want to bind to using the defines from this answer (maybe I should have found that first before typing all this out :).

显然,您还可以指定您想要使用这个答案的定义绑定的确切版本(也许我应该在输入所有这些之前先找到它:)。

If you find it is your application that binds to 9.0.30729.1 and the dependant library is binding to 9.0.21022.8 then you simply need to remove the preprocessor definition.

如果您发现是您的应用程序绑定到9.0.30729.1,并且依赖库绑定到9.0.21022.8,那么您只需删除预处理器定义。

The other difficulty is that when you upgrade Visual Studio, the runtime merge modules in your redistributable folder are also upgraded to those versions. So if you have a setup project that uses those merge modules and you are trying to bind to the default version you would end up installing the new versions of the runtimes.

另一个困难是,当您升级Visual Studio时,可再分配文件夹中的运行时合并模块也会升级到这些版本。所以如果你有一个安装项目使用这些合并模块并且你试图绑定到默认版本你最终会安装运行时的新版本。

Resolving the runtime version would not be a problem if you also distribute the runtime policy merge modules, as the library loader will at runtime look at the policy of your runtime and automatically load the newest version even if you bind to the default version. Even with private assemblies the loader will first look in the WinSxS folder so if the policies are there you will bind to the newest version. So your mixed version numbers in your manifest will both redirect to the newest version.

如果您还分发运行时策略合并模块,那么解析运行时版本就不是问题,因为库加载程序将在运行时查看运行时策略并自动加载最新版本,即使您绑定到默认版本。即使使用私有程序集,加载程序也会首先查看WinSxS文件夹,因此如果有策略,您将绑定到最新的版本。所以您的混合版本号在您的清单将重定向到最新的版本。

Sometimes that is not desired and you can control that to force it to load only the version in the manifest that you specify, which is explained in an answer to this similar SO question.

有时,这是不需要的,您可以控制它只加载您指定的清单中的版本,这在类似SO问题的答案中有解释。