MonoTouch/MonoDroid 中的可移植类库强汇编引用问题 [英] Portable Class Library strong assembly reference problems in MonoTouch/MonoDroid

查看:28
本文介绍了MonoTouch/MonoDroid 中的可移植类库强汇编引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PCL 在 MonoTouch 和 MonoDroid 中运行良好.

PCLs do work well in MonoTouch and MonoDroid.

但是,有时,当我使用变量来引用 PCL 中的类型,然后我尝试在 MonoX 客户端中使用相同的引用时,编译器会失败并显示如下消息:

However, sometimes, when I use a variable to reference a Type in a PCL, and then I try to use that same reference in a MonoX client, then the compiler fails with a message like:

类型System.Collections.Specialized.INotifyCollectionChanged"是在未引用的程序集中定义的.您必须添加对程序集System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes"的引用.

The type 'System.Collections.Specialized.INotifyCollectionChanged' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'.

这里的问题是,在 MonoDroid 中,我的 System.Collections.Specialized.INotifyCollectionChanged PCL 是在 shim 类型转发 DLL 中提供的 - 如 https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/System.Windows - 显然 DLL 不能使用 Microsoft 的私钥进行签名.

The problem here is that in MonoDroid my System.Collections.Specialized.INotifyCollectionChanged PCL is provided in a shim Type Forwarding DLL - like https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/System.Windows - and obviously that DLL cannot be signed using Microsoft's Private Key.

更多信息:

  • 这在 ICommand 和 INotifyCollectionChanged 等接口中很常见
  • 它似乎只发生在 .exe 项目中(库以某种方式工作正常)
  • 我主要在 VS2010 和 VS2012 中进行测试/构建
  • 更多信息:https://github.com/slodge/MvvmCross/issues/41

任何人都可以提出任何解决此问题的方法吗?例如有没有办法关闭强大的程序集命名保护?

Can anyone suggest any way to resolve this? e.g. is there a way of turning the strong assembly naming protection off?

我认为如果要在 Microsoft 发布的 .Net 实现之外真正实现 PCL 的可移植性,这是必要的吗?

I think this is needed if PCLs are to be truly Portable outside of Microsoft shipped .Net implementations?

推荐答案

从管理员 VS 命令提示符,您可以运行:

From an admin VS command prompt, you can run this:

sn -Vr *,7cec85d7bea7798e

这将跳过任何以 7cec85d7bea7798e 作为公钥令牌的程序集的强名称验证.然后您应该能够延迟使用该密钥对您的 shim DLL 进行签名.我认为您可以使用 sn -pc 从 DLL 中提取密钥的公共部分,以便将其用于延迟签名.

This will skip strong name verification for any assembly with 7cec85d7bea7798e as the public key token. Then you should be able to delay sign your shim DLL with that key. I think you can use sn -pc to extract the public portion of a key from a DLL in order to use it for delay signing.

这应该允许您使用垫片进行编译.当然,它也需要在运行时工作.我认为 MonoTouch 和 MonoDroid 实际上并没有验证程序集的强名称键,所以它会起作用.如果他们确实进行了此验证,那么我认为您无能为力.在这种情况下,Mono 需要进行一些更改以支持这些类型引用或忽略填充程序的密钥,或者 Microsoft 需要提供您可以使用的填充程序 DLL 的签名版本.

This should allow you to compile using the shims. Of course, it also needs to work at runtime. I think that MonoTouch and MonoDroid don't actually validate the strong name keys for assemblies, so it will just work. If they do do this validation, then I don't think there's much you can do. In that case either Mono would need to make some changes to support these type references or ignore the key for the shims, or Microsoft would need to provide signed versions of the shim DLLs you can use.

请注意,我不是安全专家,因此我不知道在您的计算机上禁用这些 Microsoft 密钥的强名称验证可能会产生什么样的安全影响.我不认为会有任何重大影响......

Note that I'm not a security expert so I don't know what kind of security impact disabling strong name validation on your machine for these Microsoft keys might have. I don't think there will be any significant impact...

丹尼尔的详细跟进:

我认为这是解决 Mono 上便携式库的类型共享/强名称签名问题所需的操作:

I think this is what you need to do to get around the type sharing / strong name signing issues for portable libraries on Mono:

-> 提取System.Windows.dll的公钥,放到Droid System.Windows工程的工程目录下:

-> Extract the public key of System.Windows.dll, and put it in the project directory for the Droid System.Windows project:

 Sn –e "C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.0ProfileProfile104System.Windows.dll" system_windows.snk

-> 使用提取的密钥修改 Droid system.windows 项目以延迟签名.将以下内容放入 csproj 文件的 PropertyGroup 中:

-> Modify the Droid system.windows project to delay-sign using the extracted key. Put the following in a PropertyGroup in the csproj file:

<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>system_windows.snk</AssemblyOriginatorKeyFile>
<DelaySign>true</DelaySign>

-> 将 Droid System.Windows 项目的程序集版本(在 AssemblyInfo.cs 中)更改为:

-> Change the assembly version of the Droid System.Windows project (in AssemblyInfo.cs) to:

2.0.5.0 

在我的测试中,我似乎不需要禁用强名称验证.所以我不认为它会给新手带来任何额外的障碍——一旦你做了这些改变,他们只需要获取你的代码,它就会正确构建.

In my testing, I didn’t seem to need to disable strong name verification. So I don’t think it will present any extra barriers for newbies – once you have these changes made they’ll just need to get your code and it will build correctly.

但是,如果确实遇到问题,请尝试从管理员 VS 命令提示符运行以下命令:

However, if you do run into problems, try running the following from an admin VS command prompt:

 sn -Vr *,7cec85d7bea7798e 

让我知道这是如何工作的!

Let me know how this works!

谢谢,

丹尼尔

这篇关于MonoTouch/MonoDroid 中的可移植类库强汇编引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆