How do I add a manifest to an executable using mt.exe?

天涯浪子 提交于 2019-11-27 17:59:47

You should use /outputresource instead of /updateresource:.

The correct command line would be:

mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;#1"
mesterak

This worked for me for VS 2005:

  1. Create text file named after executable with extension manifest, and ensure it is located in the same path as your code files; i.e. Form1.cs, etc. For example, if your app name is UACTester.exe then your manifest file should be named UACTester.exe.manifest.
  2. Ensure the contents of the manifest is good. I use this one:
    <?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" />
        <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
            <security>
                <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
                    <requestedExecutionLevel level="requireAdministrator" 
                     uiAccess="false" />
                </requestedPrivileges>
                <applicationRequestMinimum>
                    <defaultAssemblyRequest permissionSetReference="Custom" />
                    <PermissionSet class="System.Security.PermissionSet" 
                     version="1" ID="Custom" SameSite="site" />
                </applicationRequestMinimum>
            </security>
        </trustInfo>
        <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
            <application>
            </application>
        </compatibility>
    </asmv1:assembly>
  1. On your executable project, add the following post-build event:

    "$(DevEnvDir)..\Tools\Bin\mt.exe" -nologo -manifest "$(TargetPath).manifest" -outputresource:"$(TargetPath)"

Hope this helps. Good luck! -Matt Esterak

You can also use it like this to embed the manifest inside the EXE file:

mt.exe -nologo -manifest "r:\shared\hl.exe.manifest" -outputresource:"r:\shared\hl33m.exe;1"

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