创建强名称托管 (/clr) C++集会

发布于 2024-10-18 23:53:38 字数 376 浏览 4 评论 0原文

我有一个使用 /clr 开关的托管 C++ 程序集,我尝试按照 这个问题具有以下构建后步骤:

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

然而,这给出了以下错误:

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

出了什么问题?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

開玄 2024-10-25 23:53:38

您是否在 AssemblyInfo.cpp 中将程序集标记为延迟签名?

[assembly:AssemblyKeyFileAttribute("MyKey.snk")];
[assembly:AssemblyDelaySignAttribute(true)];

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

[assembly:AssemblyKeyFileAttribute("MyKey.snk")];
[assembly:AssemblyDelaySignAttribute(true)];
花辞树 2024-10-25 23:53:38

我最终弄清楚了这一点 - 根据链接的问题,我不能只设置 Linker/Advanced/KeyFile 选项并期望它起作用 - 我需要使用 sn.exe 对程序集进行签名,但是我仍然需要设置Linker/Advanced/KeyFile选项。

简而言之,要签署 /clr 程序集,您需要执行以下操作:

  1. Linker/Advanced/KeyFile 属性页中指定密钥文件
  2. 使用 sn.exe 将程序集签名为帖子-build 步骤

(我相信使用 [assemble:AssemblyKeyFileAttribute("MyKey.snk")] 相当于在项目属性对话框中设置密钥文件)。

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).

烙印 2024-10-25 23:53:38

标记的答案有助于达成最终解决方案(因此它收到了我的+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

The marked answer helped to reach the final solution (so it receives a +1 from me).

However had to spent several frustrating minutes figuring out how to create an AssemblyInfo.cpp in VS2010.

Below is the "more" complete answer to the problem.

#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)];

Then as a post-build step, run sn -Ra YourAssembly.dll YourAssembly.snk

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文