In a previous article, I explored the ability to add a manifest as a resource to a compiled executable. This process allowed for XP themes to display correctly without the burden of yet another file to manage when distributing an application. The down side to my first article is that the process of injecting the manifest is cumbersome and is required each time the source code is compiled.
This article aims at streamlining the process of injecting the manifest in a “hands-off” manner by automatically injecting the manifest on the completion of each new build. The solution uses the Post-build property of a project to call a console version of the manifest injector, so no extra work is required when building the project.
To set up a project, first download the source for this article. Make note of the path to the ManifestConsole.exe. Now open a Windows Forms project and open up the project properties dialog. Select the Build Events option on the left. Click in the box for the Post-build Event Command Line. Click on the ellipsis button to open up the Post-build editor.
The editor is where we’ll specify the path and arguments to call the ManifestConsole.exe. The ManifestConsole.exe requires two command line arguments. The first argument is the path to the target executable (i.e., which EXE to inject the manifest into). The second argument is the path to the manifest (for this example, it’s your project’s root directory).
An example of the command is as follows:
C:\ManifestInjection\ManifestConsole\bin\Release\ManifestConsole.exe $(TargetPath) $(ProjectDir)WindowsApplication1.exe.manifest
Ready to Build
If we dissect this command line, we’ll see three things. First is the path to the ManifestConsole.exe file. For now, this is the same location you put the source for this article. Change the C:\<path> accordingly. The first command line argument, $(TargetPath), will be filled in by Visual Studio with the EXE you are building. The last argument, $(ProjectDir)WindowsApplication1.exe.manifest, points to your project directory to a file named WindowsApplication1.exe.manifest. Change this argument to point to your manifest and you’re ready to build your project. *Note:* click the Macros button on the editor window for a list of paths Visual Studio .NET supports. Check the Output window for status on the injection process when you build your project. Now… run your app! Don’t you just love automation?
I'm the founder of PageLabs, a web-based performance and SEO optimization site.
Give your site a boost in performance, even take a free speed test!