Donnerstag, 24. März 2011

Shipping Manifests

Hello there

In this article we will have a look how to ship a manifest with your application. If you need to know what a manifest is please reference to this article.

There are different ways to deploy a manifest with your application. I will refer on how to achieve it using the Microsoft IDE (either for C# or C++ respectively).
  1. In C++ you can directly modify the default manifest using a #pragma directive or the project settings
  2. In C++ you can directly create a manifest as a resource of your application
  3. In C# you have to possibility to add a manifest as a project object and select it as default one
  4. For every component you can ship the manifest as separate file (not recommended!)
Now lets explain this a bit more:

Modify the default manifest 
To modify the manifest directly inside your code you can use the #pragma comment(linker, "...") directive. This is an example how this would look like:

#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

This adds a dependent assembly to the manifest (reference article linked above if you need to know what a dependent assembly is). The same can also be achieved if you go to your project properties. There in the category linker you find the property page "Manifest file". This looks like the following:

There you can modify the manifest as you like to.

Add a manifest resource
Adding a manifest as a resource is very easy. You can simply create your manifest as you like and add it to the executable with resource type RT_MANIFEST or 24. Its recommended that you choose the name taken in the assemblyIdentity part inside the manifest followed by .manifest as name of the resource. Thats it!

Add a manifest inside C#Adding manifests in C# is even simpler. Right click into your project and choose Add -> New Item. In the dialog scroll down until you find "Application manifest file" and give it a name. It creates the default entries and lists it in the solution explorer. You can now edit the manifest inside the editor. If you want to make your manifest the default one visit the project settings and go to the "Application" tab. There you find a region with "Resources" which contains a drop down list with possible manifest files to use. Thats it!

So adding manifests is a very easy thing to do and its worth it ;)

Thanks for reading and goodbye

Keine Kommentare:

Kommentar veröffentlichen