Flyover Country

Aaron Brethorst on Politics, User Experience, and Photography. I like sushi.

Flyover Country header image 2

Meet UAC - Embedding Manifests in Managed Apps

February 25th, 2007 · 2 Comments

Over the past few blog posts, we’ve looked into what Virtualization and run levels are all about, and learned how to create a Fusion manifest that is appropriate for inclusion on Windows Vista. When we created that Fusion manifest for Windows Vista, we never solved the problem of how to include it in your application. I gave you a hand-wavy answer about including the manifest file side-by-side with your app. This is an okay solution, but certainly not a great one. Ideally, we’d be able to embed our manifest directly into our managed exe, just like the big dogs do with their fancy native apps.

Today, we’re going to do just that. It’s actually surprisingly easy to accomplish this with Visual Studio 2005, due to the awesomeness of the managed Project system and MSBuild (not that I’m biased or anything ;-) ).

Step 1: Locate the Project in Solution Explorer that builds your executable.

Step 2: Double-click on the Properties node in Solution Explorer.

Step 3: Click on the Build Events tab in the App Designer (or Project Designer, or whatever it’s called).

Step 4: Add the following text to the Post-Build Steps:

“C:\Program Files\Microsoft Visual Studio 8\Common7\Tools\Bin\mt.exe” -manifest “$(ProjectDir)Borealis.exe.manifest” -outputresource:$(TargetDir)Borealis.exe;#1

Clearly, you should make sure that the path to mt.exe jives with the installation location on your machine, and you should name the manifest and output executable files according to what they’re actually called for your project (hey, what’s Borealis?). But yeah, otherwise you’re done. That was pretty easy, no? Check out the screenshot below.

Virtualization Disabled

Tags: UAC · Vista

2 responses so far ↓

  • 1 Michael Bone // Mar 21, 2007 at 10:06 pm

    Be aware, too, that if you strong name your assembly then you’ll need to re-sign it after running mt.exe.

    Here are the post-build events I successfully used in my Visual Studio 2005 C# project (run “When the build updates the project output”).

    “$(VS80COMNTOOLS)Bin\mt.exe” -manifest “$(ProjectDir)$(ProjectName).manifest” -outputresource:”$(TargetDir)$(TargetFileName)”;#1

    “$(VS80COMNTOOLS)..\..\SDK\v2.0\Bin\sn.exe” -R “$(TargetDir)$(TargetFileName)” “$(ProjectDir)$(ProjectName).snk”

    (I named my manifest file MyProjectName.manifest rather than MyProjectName.exe.manifest.)

  • 2 Bob Pearson // Sep 14, 2007 at 10:05 am

    Just a follow-up to the above, if you are using .pfx (password protected key instead of .snk) you will want to use signtool.exe instead of sn.exe. Here is an example:

    “$(VS80COMNTOOLS)Bin\mt.exe” -manifest “$(ProjectDir)$(TargetFileName).manifest” -outputresource:$(TargetDir)$(TargetFileName);#1
    “$(VS80COMNTOOLS)Bin\signtool.exe” sign /a $(TargetDir)$(TargetFileName)

Leave a Comment