我有一個託管C++使用/clr
開關,我想每this question爲標誌的下面生成後步驟組裝:創建一個強命名的管理(/ CLR)C++組件
sn -Ra "$(TargetPath)" MyKey.snk
然而這是給出以下錯誤:
C:\Path\Assembly.dll does not represent a strongly named assembly
什麼問題出在哪裏?
我有一個託管C++使用/clr
開關,我想每this question爲標誌的下面生成後步驟組裝:創建一個強命名的管理(/ CLR)C++組件
sn -Ra "$(TargetPath)" MyKey.snk
然而這是給出以下錯誤:
C:\Path\Assembly.dll does not represent a strongly named assembly
什麼問題出在哪裏?
您是否在AssemblyInfo.cpp中標記了用於延遲簽名的程序集?
[assembly:AssemblyKeyFileAttribute("MyKey.snk")];
[assembly:AssemblyDelaySignAttribute(true)];
我到底想通這一個 - 按照鏈接的問題,我不能只設置Linker/Advanced/KeyFile
選項,並期望它的工作 - 我需要使用sn.exe
簽署組裝,但是我也仍需要設置Linker/Advanced/KeyFile
選項。
總之簽署/ CLR程序集,你需要兩個:
Linker/Advanced/KeyFile
屬性頁sn.exe
指定密鑰文件簽署大會作爲生成後步驟(我相信使用[assembly:AssemblyKeyFileAttribute("MyKey.snk")]
相當於在項目屬性對話框中設置密鑰文件)。
它應該工作,但有時它不會,你必須使用屬性。 – surfen
marked answer幫助達成最終解決方案(所以它從我那裏收到+1)。
但是,不得不花了幾分鐘的時間才知道如何在VS2010中創建一個AssemblyInfo.cpp
。
下面是問題的「更多」完整答案。
#include "stdafx.h"
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::CompilerServices;
using namespace System::Runtime::InteropServices;
using namespace System::Security::Permissions;
[assembly:AssemblyKeyFileAttribute("YourAssembly.snk")];
[assembly:AssemblyDelaySignAttribute(true)];
然後作爲生成後步驟,運行sn -Ra YourAssembly.dll YourAssembly.snk
我在[assembly]屬性後需要分號。 – Anton
哪裏去這在託管C++組件? – Justin
看到[這裏](http://stackoverflow.com/questions/158821/managed-c-assembly-attributes) – adrianm
所以該死的討厭,這是/沒有記錄。花了兩天時間試圖找出爲什麼切換到32位配置時不起作用,但不需要w/64位。 – bbqchickenrobot