Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a strongly-named managed (/clr) C++ assembly

Tags:

c++

.net

clr

sign

I have a managed C++ assembly using the /clr switch that I am trying to sign as per this question with the following post-build step:

sn -Ra "$(TargetPath)" MyKey.snk

However this is giving the following error:

C:\Path\Assembly.dll does not represent a strongly named assembly

What is going wrong?

like image 522
Justin Avatar asked Feb 25 '11 12:02

Justin


2 Answers

Have you marked the assembly for delay signing in AssemblyInfo.cpp?

[assembly:AssemblyKeyFileAttribute("MyKey.snk")];
[assembly:AssemblyDelaySignAttribute(true)];
like image 58
adrianm Avatar answered Oct 26 '22 23:10

adrianm


I figured this one out in the end - as per the linked question I cannot just set the Linker/Advanced/KeyFile option and expect it to work - I need to use sn.exe to sign the assembly, however I also still need the Linker/Advanced/KeyFile option to be set.

In short to sign a /clr assembly you need to both:

  1. Specify a keyfile in the Linker/Advanced/KeyFile properties page
  2. Use sn.exe to sign the assembly as a post-build step

(I believe that using the [assembly:AssemblyKeyFileAttribute("MyKey.snk")] is equivalent to setting the keyfile in the project properties dialog).

like image 33
Justin Avatar answered Oct 26 '22 23:10

Justin