1.4. Compiling the Manifest into the Application
In most cases, you won't use a separate manifest file . The only exception is when you're absolutely certain the
administrator will need to make changes to the application manifest at
some point (and even then, using a separate manifest is a dangerous
proposition). Compiling the manifest into the application prevents
anyone from modifying (at least with any ease). In addition, compiling
the manifest into the application means that the manifest won't get
lost. To compile the manifest into the application, you use MT.EXE, a utility that comes with the Windows 7 SDK.
You need to add a special command to the project
before Visual Studio will compile the manifest file for you. Use these
steps to configure the application to compile the manifest into the
executable:
Right-click
the project entry in Solution Explorer and choose Properties from the
Context menu. You'll see the Audit Activity properties window.
Select the Build Events tab.
Click Edit Post-build to display the Post-build Event Command Line dialog box shown in Figure 1.
Type the following command in the dialog box (as a single line, rather than on multiple lines as shown in the book):
"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\MT.EXE"
-manifest "$(ProjectDir)$(TargetName).exe.manifest"
–outputresource:"$(TargetDir)$(TargetFileName)";#1
You need to provide the actual path to MT.EXE as part of the command. The –manifest
command line switch tells the Manifest Tool (MT) utility where to
locate the manifest file you want to compile, which is normally the
same folder as the source code for your application. The $(ProjectDir) macro points to this location, while the $(TargetName) macro provides the name of the application. The –outputresource command line switch provides the location of the executable that should receive the manifest. The $(TargetDir) macro provides the location of the executable (including whether the output is in the Release or Debug folder), and the $(TargetFileName) macro provides the name of the executable file.
Click OK. The Build Events tab should now contain a command like the one shown in Figure 2.
Choose Build => Build Solution. The application will build as normal. You should see a successful MT utility entry, as shown in Figure 3, in the Output window.
1.5. Executing the Application
The result of compiling the manifest into the
executable is no different from working with the manifest file
separately. When you start to debug the application, you'll still see
the Visual Studio notification shown in Figure 4.
The debugger will still start the application as normal and you'll
still see a UAC dialog box. Everything will work as before. The only
difference is that the manifest file is contained within the
executable, rather than appearing as a separate file.