如何将程序集清单添加到.NET可执行文件? [英] How to add an assembly manifest to a .NET executable?

查看:115
本文介绍了如何将程序集清单添加到.NET可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向我的.NET可执行文件添加程序集清单?

How can i add an assembly manifest to my .NET executable?

程序集清单是将XML文件添加到资源类型为RT_MANIFEST(24)的.NET可移植可执行文件(PE)中.

An assembly manifest is is an XML file that is added to a .NET portable executable (PE) with resource type RT_MANIFEST (24).

汇编清单用于声明有关可执行文件的许多信息,例如:

Assembly manifests are used to declare a number of things about the executable, e.g.:

  • 如果我想成为一名优秀的开发人员,请禁用DPI缩放:

  • If i want to disable DPI-scaling because i am a good developer:

<!-- We are high-dpi aware on Windows Vista -->
<asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
   <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
      <dpiAware>true</dpiAware>
   </asmv3:windowsSettings>
</asmv3:application>

  • 我可以声明我是在Windows 7上进行设计和测试的,我应该继续依赖Windows 7中的所有错误

  • i can declare that i was designed and tested on Windows 7, and i should continue to depend on any bugs in Windows 7

    <!-- We were designed and tested on Windows 7 -->
    <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
       <application>
          <!--The ID below indicates application support for Windows 7 -->
          <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
       </application>
    </compatibility>
    

  • 我可以宣布自己是一名优秀的开发人员,不需要文件和注册表虚拟化

  • i can declare that i am a good developer, and don't need file and registry virtualization

    <!-- Disable file and registry virtualization -->
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
       <security>
          <requestedPrivileges>
             <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
          </requestedPrivileges>
       </security>
    </trustInfo>
    

  • 我可以声明我依赖于 Microsoft Common Controls 库的特定版本6:

  • i can declare that i depend on a particular version 6 of the Microsoft Common Controls library:

    <!-- Dependency on Common Controls version 6 -->
    <dependency>
       <dependentAssembly>
          <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="X86"
                publicKeyToken="6595b64144ccf1df"
                language="*"/>
       </dependentAssembly>
    </dependency>
    

  • 我可以声明我依赖于特定版本的GDI +:

  • i can declare that i depend on a particular version of GDI+:

    <dependency>
       <dependentAssembly>
          <assemblyIdentity type="win32" name="Microsoft.Windows.GdiPlus" version="1.0.0.0" processorArchitecture="x86"
                publicKeyToken="6595b64144ccf1df" language="*" />
       </dependentAssembly>
    </dependency>
    

  • 在过去的日子,我们将创建一个资源脚本文件(*.rc),例如:

    In the olden days, we would create a resource script file (*.rc), e.g.:

    wumpa.rc

       1    24    AssemblyManifest.xml
    

    将该文件添加到项目中,然后编译器将编译.rc文件;在最终的可执行映像中包含资源.

    add that file to the project, and the compiler would compile the .rc file; including resources in the final executable image.

    除了 Visual Studio 2010不会似乎没有办法将资源脚本文件添加到项目中..

    如何在Visual Studio 2010中将资源脚本添加到项目中?

    How do i add a resource script to a project in Visual Studio 2010?

    如何在Visual Studio 2010中将程序集清单添加到项目中?

    How do i add an assembly manifest to a project in Visual Studio 2010?

    注意:任何解决方案都必须在具有源代码控制和多个开发人员的环境中工作(例如,可能未安装的二进制文件的硬编码路径会破坏构建,并且不起作用).

    Note: Any solution must work in an environment with source control and multiple developers (e.g. hard-coded paths to probably not installed binaries will break the build and not work).

    • VS2010/.NET: How to embed a resource in a .NET PE executable?
    • VS2005: How to embed a manifest in an assembly: let me count the ways... (can't be done)

    更新:Michael Fox建议使用项目属性对话框来包含程序集清单,但他未指出其中:

    Update: Michael Fox suggests that the project properties dialog can be used to include an assembly manifest, but he doesn't indicate where:

    更新:我尝试过的事情:

    • 在项目属性屏幕上,选择应用.选择单选选项图标和清单.在清单下,保留默认选项Embed manifest with default settings:
    • From the project properties screen, select Application. Select radio option Icon and Manifest. Under Manifest leave the default option of Embed manifest with default settings:

    不起作用,因为它嵌入了具有默认设置而不是我的设置的清单.

    Doesn't work because it embeds a manifest with default settings, rather than my settings.

    • 清单下,将组合选项更改为Create application without a manifest:

    • Under Manifest, change the combo option to Create application without a manifest:

    不起作用,因为它没有嵌入清单

    资源下,选择资源文件单选选项:

    不起作用,因为您无法选择程序集清单(或包含程序集清单的资源脚本)

    资源下,选择资源文件单选选项,然后输入程序集清单XML文件的路径:

    Under Resources, select the Resource File radio option, then enter the path to an assembly manifest XML file:

    不起作用,因为当出现带有程序集清单的Visual Studio时出现了阻塞:

    • 资源下,选择资源文件单选选项,然后输入资源脚本文件的路径:
    • Under Resources, select the Resource File radio option, then enter the path to a resource script file:

    不起作用,因为当出现资源脚本时,Visual Studio会阻塞:

    • AssemblyManifest.xml添加到我的项目中,然后在清单组合框中查找它:

    • Add the AssemblyManifest.xml to my project, then look for it in the Manifest combo box:

    不起作用,因为未将Assembly Manifest文件列为选项

    我还有很多其他事情可以保留屏幕快照(将.rc文件添加到解决方案中,在下拉列表中查找它,选择无清单",然后将wumpa.rc生成操作更改为各种内容,生成.rc文件,请使用单独的资源编译器(手动)或pre-build/msbuild步骤,然后选择该.res文件作为我的资源).我将停止在问题中增加多余的内容,并希望得到答案.

    i have a dozen other things i can keep screenshotting (add a .rc file to the solution, look for it in the dropdown, select "no manifest" and change the wumpa.rc build action to various things, build the .rc file using a separate resource compiler, either manually, or a pre-build/msbuild step, and select that .res file as my resource). i'll stop adding extra bulk to my question and hope for an answer.

    推荐答案

    如果要将自定义信息添加到应用程序的清单中,可以按照以下步骤操作:

    If you want to add custom information to your application's manifest, you can follow these steps:

    1. 在解决方案资源管理器中右键单击该项目.
    2. 点击添加新项".
    3. 选择应用程序清单文件".

    这会将名为app.manifest的文件添加到您的项目中,您可以根据需要打开和修改该文件.

    This adds a file named app.manifest to your project, which you can open and modify as desired.

    带有屏幕截图的类似步骤来自在MSDN上将托管应用程序声明为DPI感知:

    Similar steps, with screenshots, lifted from Declaring Managed Applications As DPI-Aware on MSDN:

    1. 在解决方案资源管理器中,右键单击您的项目,指向 Add ,然后单击 New Item .

    添加新项对话框中,选择应用程序清单文件,然后单击添加.出现app.manifest文件.

    In the Add New Item dialog box, select Application Manifest File, and then click Add. The app.manifest file appears.

    将以下文本复制并粘贴到 app.manifest 文件中,然后保存.

    Copy and paste the following text into the app.manifest file and then save.

    <?xml version="1.0" encoding="utf-8"?>
    <asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" 
                    xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" 
                    xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" 
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    
      <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
    
        <!-- Disable file and registry virtualization. -->
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
          <security>
            <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
             <requestedExecutionLevel level="asInvoker" uiAccess="false" />
             <!--  <requestedExecutionLevel  level="asInvoker" uiAccess="false" />
                   <requestedExecutionLevel  level="requireAdministrator" uiAccess="false" />
                   <requestedExecutionLevel  level="highestAvailable" uiAccess="false" />
             -->
            </requestedPrivileges>
          </security>
        </trustInfo>
    
        <!-- We are high-dpi aware on Windows Vista -->
        <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
          <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
            <dpiAware>true</dpiAware>
          </asmv3:windowsSettings>
        </asmv3:application>
    
        <!-- Declare that we were designed to work with Windows Vista and Windows 7-->
        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
          <application>
            <!--The ID below indicates application support for Windows Vista -->
            <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
            <!--The ID below indicates application support for Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
          </application>
        </compatibility>
    
        <!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
        <dependency>
          <dependentAssembly>
            <assemblyIdentity
                type="win32"
                name="Microsoft.Windows.Common-Controls"
                version="6.0.0.0"
                processorArchitecture="*"
                publicKeyToken="6595b64144ccf1df"
                language="*"
            />
          </dependentAssembly>
        </dependency>
    
      </asmv1:assembly>
    

  • 在解决方案资源管理器中,右键单击项目,然后单击属性以验证 app.manifest 使用.

  • In the Solution Explorer, right-click on the project, and then click Properties to verify that the app.manifest is used.

    您的应用程序现已显示为为Windows设计"所需,并且是

    Your application is now manifested as required to be "designed for Windows", and is

    • 禁用文件和注册表虚拟化
    • 禁用应用程序的DWM扩展
    • 宣布您是在Windows 7和Windows Vista上进行设计和测试的.
    • 依赖于Common Controls库版本6(允许公共控件使用视觉样式)

    这篇关于如何将程序集清单添加到.NET可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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