How to use manifests with build.exe

Posted on

As of Windows Vista, basically all applications require a manifest in order to at least declare UAC compliance. Visual Studio has builtin support for creating and embedding manifests, so when using VS to build applications, using manifests is straightforward. However, when building a user mode application with the WDK and build.exe, things are a little different. Looking at the WDK documentation, manifests remain unmentioned – both in the context of UAC and SXS. Judging from documentation, it seems that the WDK does not provide any support for embedding manifests – which would mean that you are left with having to poke with the makefiles in order to invoke mt somewhere.

Looking at makefile.new, however, reveals that there are plenty of manifest-related rules and as it turns out, there indeed is support for manifests. On lines 1866 to 1925 (WDK 6000), makefile.new even contains a short documentation about the usage of manifests – so whether manifest support being unmentioned in the official docs is intentional or not is not quite clear. However, using the information in makefile.new, it is straightforward to get build.exe to embed manifests in a binary.

To embed a manifest, first create the manifest file and name it myapp.manifest. In the SOURCES file, include these lines:

    SXS_APPLICATION_MANIFEST=myapp.manifest
    SXS_ASSEMBLY_VERSION=1.0
    SXS_ASSEMBLY_NAME=MyApp
    SXS_ASSEMBLY_LANGUAGE=0000
    

That’s it.

In order not to have to provide a separate manifest file for different processor builds, there is some preprocessing taking place before the manifest is embedded. The following macros are available for use in the manifest:

  • SXS_ASSEMBLY_NAME (set in SOURCES)
  • SXS_ASSEMBLY_VERSION (set in SOURCES, defaults to 5.1.0.0)
  • SXS_ASSEMBLY_LANGUAGE (set in SOURCES, LCID or 0000 for neutral)
  • SXS_PROCESSOR_ARCHITECTURE (set automatically)

When using these macros, note that they will be replaced by quoted text – as a consequence, you have to use them – a bit unintuitively – as follows (Note the missing quotes!):

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly 
         xmlns="urn:schemas-microsoft-com:asm.v1" 
         manifestVersion="1.0"
      <assemblyIdentity version=SXS_ASSEMBLY_VERSION
         processorArchitecture=SXS_PROCESSOR_ARCHITECTURE
         name=SXS_ASSEMBLY_NAME/
      <description>Example</description>
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
        <security>
          <requestedPrivileges>
            <requestedExecutionLevel level="asInvoker" 
              uiAccess="false"/>
          </requestedPrivileges>
        </security>
      </trustInfo>
    </assembly>
    

After preprocessing, the file is embedded into the binary as follows:

    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <!--  Copyright (c) Microsoft Corporation --
    <assembly 
         xmlns="urn:schemas-microsoft-com:asm.v1" 
         manifestVersion="1.0">
      <assemblyIdentity version="1.0.0.0" 
         processorArchitecture="AMD64" 
         name="MyApp" /
      <description>Example</description
      <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
        <requestedPrivileges>
          <requestedExecutionLevel level="asInvoker" 
            uiAccess="false" /
        </requestedPrivileges>
      </security>
      </trustInfo>
    </assembly>
    

« Back to home