一分钟明白 VS manifest 原理

什么是vs 程序的manifest文件

manifest 是VS程序用来标明所依赖的side-by-side组建,如ATL, CRT等的清单。

为什么要有manifest文件

一台pc上,用一组建往往会有不止一个版本(c:/windows/winsxs或系统目录下),程序在加载的时候,不知加载哪个,于是manifest文件来指明。

manifest在哪儿,如何创建。

如果用VS开发,可以Set通过porperty->configuration properties->linker->manifest file->Generate manifest To Yes来自动创建manifest来指定系统的和CRT的assembly版本。

除了这样产生外部的manifest file,还有embedded manifest信息可以被写到所生成的二进制文件内

Set porperty->configuration properties->manifest tool->embed manifest  To Yes

对于xp及早前的windows版本,external manifest会比embed manifest有更高的优先级,但对于windows server及后的版本,相反。

为什么我的manifest明明指明

name="Microsoft.VC80.DebugCRT" version="8.0.50608.0",

但是用depends.exe工具却发现引用的是8.00.50727.42呢?

因为在C:/WINDOWS/WinSxS/Policies下,有publisher configuration file也叫policy文件,如8.0.50727.42.policy文件对依赖做了重定向:

<dependentAssembly>
<assemblyIdentity type="win32" name="Microsoft.VC80.DebugCRT" processorArchitecture="ia64" publicKeyToken="1fc8b3b9a1e18e3b"/>
<bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
</dependentAssembly>

指明"8.0.41204.256-8.0.50608.0"都被定向到8.0.50727.42。这是assembly提供商如MS对低级版本bug的修正而提供的解决方法。除此之外,你也可以用application config文件来对本程序做assembly的重定向。如在你bin local文件夹下 yourbin.extention.config:

<configuration>
       <windows>
           <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
        <assemblyIdentity type="win32" name="Microsoft.VC80.ATL" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
        <bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
          </dependentAssembly>
          <dependentAssembly>
        <assemblyIdentity type="win32" name="Microsoft.VC80.DebugCRT" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"/></assemblyIdentity>
        <bindingRedirect oldVersion="8.0.41204.256-8.0.50608.0" newVersion="8.0.50727.42"/>
          </dependentAssembly>
       </assemblyBinding>
       </windows>
</configuration>

如何决定我程序manifest信息所指定的assembly版本信息?

在assembly头文件中,assembly的版本信息被指明了。如crtassem.h中

#ifndef _CRT_ASSEMBLY_VERSION
#define _CRT_ASSEMBLY_VERSION "8.0.50608.0"
#endif

可以修改8.0.50608.0为8.0.50727.42以产生你想要的manifest信息。

若我想将我的程序发布为独立程序集(isolated application),不去依赖目标pc的系统assembly,该怎么办?

带上所有依赖的assembly和相应的manifest文件(c:/windows/winsxs),注意,manifest信息要直接可以指定到所附带的assembly DLLs,不需要依赖policy的重定向。

### Visual Studio 2019 Manifest Configuration and Issues In Visual Studio 2019, the manifest file plays a crucial role in defining dependencies and configurations for applications. The application manifest is an XML-based resource embedded into the executable or DLL files. The manifest can specify various aspects including required runtime versions, security settings, and dependent assemblies. For troubleshooting purposes related to manifests: - **Manifest Generation**: By default, Visual Studio generates a standard manifest during build processes which includes common settings such as dependency information on system libraries like Common Controls[^1]. - **Customizing Manifests**: Developers may customize these generated manifests by editing them directly through project properties under "Application" tab -> "View Windows Settings..." button where one could add custom entries or modify existing ones[^2]. - **Common Problems**: - Missing Dependencies: If there are missing components specified within the manifest but not present at runtime. - Version Conflicts: When different parts of your solution require conflicting versions of shared resources listed inside their respective manifests. For resolving issues with manifests specifically in VS2019 projects, consider checking whether all necessary external references have been properly added via NuGet packages rather than manually modifying the .NET Framework version targeted by the project itself unless absolutely needed due to specific feature requirements[^3]. Additionally, ensure compatibility between target platforms when dealing cross-platform development scenarios involving multiple operating systems or architectures. ```xml <!-- Example snippet showing part of typical app.manifest --> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df"/> ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值