How to add manifest to a .NET DLL?
Asked Answered
D

3

12

I have a c# class library project that uses a COM dll registered on the system. I now want to deploy the COM dll as a side-by-side assembly, so I don't have to register it, or interfere with other applications that might use a different version of the dll.

I have added app.manifest to the c# project using the add new item menu, but I'm not sure what to do next. In the project properties/application/icon and manifest, the manifest drop down is disabled. I don't know how to get past that. I've added a manifest file, why is it not in the dropdown list?

I have a manifest for the COM dll that works with C++ applications, and I think I keep that as is. Now I need to know how to edit the app.manifest for the c# project. I will start by adding a known good dependency element. But I need a tutorial on how to set this up, I don't see it covered anywhere.

I am using VS2008

Demisemiquaver answered 14/12, 2009 at 7:53 Comment(1)
I see that the manifest box is enabled for an exe project. Does a class library project never take a manifest?Demisemiquaver
D
12

You definitely can embed a manifest in a .net dll. The contents of an application manifest do not all apply to an assembly, but some do. For example, the UAC entries don't make sense for a component manifest, but assemblyIdentity does.

Using the MT.EXE tool, you can embed a manifest into a dll:

Embed:

mt.exe -manifest filename.dll.manifest -outputresource:filename.dll;#2

Extract:

mt.exe -inputresource:filename.dll;#2 -out:filename.dll.extracted.manifest

Here are more links on related info:

Another dll embed example: http://msdn.microsoft.com/en-us/library/ms235591(v=VS.100).aspx

A SxS walkthrough: http://msdn.microsoft.com/en-us/library/ms973915.aspx

Drawbar answered 6/5, 2011 at 22:32 Comment(0)
C
3

The only thing that prevents you adding a manifest to a NET dll is the Visual Studio IDE. It can be circumvented very easily by modifying the .csproj directly - add the ApplicationManifest property in an appropriate property group. Add a manifest to an exe project and examine the .csproj for details.

Much easier than using MT.exe, which will replace the existing manifest (which you usually don't want to happen).

Chape answered 2/6, 2018 at 11:31 Comment(0)
C
2

In most applications, a manifest is typically applied to EXEs/host apps - as this is the level at which one understands how all the dependent assemblies and their capabilities mesh together.

For example, in the case of setting the UAC marker via the trustinfo/security/requestedPrivileges/requestedExecutionLevel element, the case of a dependent assembly legitimately being able to say "I say we all understand about UAC" doesn't make sense.

Chane answered 16/12, 2009 at 13:24 Comment(5)
Yes I found that out. Do you know anything about manifest caching by the OS?Demisemiquaver
Sorry, dont know anything about caching (OTTOMH guess: isnt it all just read out of the EXE's resources at load time and any caching would be transparent - I guess you wouldnt be asking if it was that straightforward!)Chane
This is not true. DLLs can contain and activate manifests. It just needs to be done manually using the activation context API.Dulciana
@DavidHeffernan I have no doubt you're right but am struggling with how to modify my answer to be less wrong. I'd def be happy with the OP unaccepting this answer as LowRider2112's answer is prob more usefulChane
@Paul On re-reading, my answer has nothing to do with your question - while my statements are [now] true they don't talk about DLLs and suggest you're incorrect in what you're asking for. I'm pretty sure it should be deleted on this basis. If it actually solved your problem, I don't mind you keeping it accepted but otherwise I'd prefer it to be unaccepted. Also if you agree it should be deleted, I'll do just thatChane

© 2022 - 2024 — McMap. All rights reserved.