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

查看:72
本文介绍了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是在填充类型转发DLL中提供的,例如 https://github.com/slodge/MvvmCross/tree/vnext/Cirrious/System.Windows -显然,无法使用Microsoft的私钥对DLL进行签名.

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
  • This is commonly seen for interfaces like ICommand and INotifyCollectionChanged
  • It only seems to occur in .exe projects (libraries somehow work OK)
  • I'm mainly testing/building in VS2010 and VS2012
  • some more at: 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作为公共密钥令牌的任何程序集,这将跳过强名称验证.然后,您应该可以使用该密钥延迟对垫片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...

丹尼尔的详细跟进工作:

Detailed follow up from Daniel:

我认为这是解决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 Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile104\System.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.

但是,如果确实遇到问题,请尝试在admin 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天全站免登陆