How to add an assembly manifest to a .NET executable?

a 夏天 提交于 2019-11-27 13:06:20
Cody Gray

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

  1. Right-click on the project in the Solution Explorer.
  2. Click "Add New Item".
  3. Select "Application Manifest File".

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


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

  1. In the Solution Explorer, right-click on your project, point to Add, and then click New Item.

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

  3. 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>
    
  4. In the Solution Explorer, right-click on the project, and then click Properties to verify that the app.manifest is used.

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

    • disables file and registry virtualization
    • disables DWM scaling of applications
    • announces that you were designed and tested on Windows 7 and Windows Vista
    • takes a dependency on Common Controls library version 6 (enabling the use of visual styles by the common controls)
Mozzis

I have Visual Studio 2010 Professional with Service Pack 1 installed. I am running on Windows 7 Ultimate 64-bit. If I follow these instructions, the project properties shows "Embed manifest with default settings" in the resources block, and also the option is disabled! When I build, the manifest does not get embedded into the DLL as I verified by opening the DLL in resource view.

However, if I :

  1. Locate the added app.manifest file in the Solution Explorer
  2. Right-click and choose Properties
  3. Change the Build Action property from "None" to "Embedded Resource"
  4. Rebuild

The manifest file is embedded properly, which I can verify by loading the DLL into the resource view. The Manifest setting in the Application properties still shows as "Embed manifest with default settings" and is still disabled.

In Visual Studio 2008, this can be done in the Project Properties window. I'm almost positive it is the same in 2010. Right click on your project, select properties, and in the application tab you can select a manifest. You have to add it to your project first, but you can do that easily by adding an existing file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!