我有一个托管的 C++ 程序集,它使用/clr
我试图根据这个问题通过以下构建后步骤签名的开关:
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")]
等同于在项目属性对话框中设置密钥文件)。
标记的答案有助于达成最终解决方案(因此它收到了我的 +1)。
然而,不得不花费数分钟来弄清楚如何AssemblyInfo.cpp
在 VS2010 中创建一个。
以下是该问题的“更多”完整答案。
#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