Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an easy way to sign a C++ CLI assembly in VS 2010?

Tags:

Right now I am setting the Linker/Advanced/KeyFile option.

I am getting the "mt.exe : general warning 810100b3: is a strong-name signed assembly and embedding a manifest invalidates the signature. You will need to re-sign this file to make it a valid assembly.".

Reading from the web, it sounds like I have to set the delay signing option, download the SDK, and run sn.exe as a post build event. Surely there must be an easier way to do this common operation in VS2010?

like image 666
jyoung Avatar asked Apr 16 '10 22:04

jyoung


People also ask

How do I sign an assembly in Visual Studio?

Create and sign an assembly with a strong name by using Visual Studio. In Solution Explorer, open the shortcut menu for the project, and then choose Properties. Under the Build tab you'll find a Strong naming node. Select the Sign the assembly checkbox, which expands the options.

How do I sign a program in Visual Studio?

You sign an application or component by using the Signing tab of the project properties window (right-click the project node in Solution Explorer and select Properties). Select the Signing tab, then select the Sign the assembly check box.


1 Answers

There's a fair amount of lameness here, this just never worked before. It got "fixed" in VS2010, mt.exe now generates a warning instead of letting this silently go wrong. Not a real fix, and there's not an obvious one, the linker can't just embed the signature and still allow mt.exe to run afterwards.

The solution is to re-sign the assembly with a post-build event. Make it look like this:

Command = sn -Ra "$(TargetPath)" $(ProjectName).snk

If you don't already have the key file, you'll need to create the .snk file yourself, run sn.exe from the Visual Studio Command prompt. for example:

cd \whereTheProjectIsLocated sn.exe -k MyProject.snk 

Or extract it from a container or use your designated key file. Delay signing is just a matter of running sn.exe with the proper command line options.

like image 132
Hans Passant Avatar answered Sep 28 '22 00:09

Hans Passant