简体   繁体   English

c# - 你可以对强名称程序集进行“弱”程序集引用

[英]c# - can you make a “weak” assembly reference to a strong named assembly

For various reasons i would rather not use strong named (signed) assemblies in my project. 由于各种原因,我宁愿不在我的项目中使用强名称(签名)程序集。 however, one of the projects is referenced by a sharepoint web part which means it must be signed. 但是,其中一个项目由sharepoint Web部件引用,这意味着它必须签名。

is it possible to have this assembly signed but when I reference it from other projects, to do so using a non-strong reference. 是否可以对此程序集进行签名,但是当我从其他项目引用它时,使用非强引用来执行此操作。 this would give me the advantages of having a non-signed assembly for the rest of my code but still allow it to be loaded by sharepoint. 这将为我提供其他代码的非签名程序集的优点,但仍然允许它由sharepoint加载。

The simplest way to do this is probably to have two different project configurations - one of which builds a strongly named assembly and one of which doesn't. 最简单的方法是使用两种不同的项目配置 - 其中一种构建一个强命名的程序集,另一种不构建。 Obviously you'll need to be careful how you build and reference the assembly, but that goes with the territory of having conflicting requirements. 显然,你需要注意如何构建和引用程序集,但这与需求冲突的领域有关。

Just keep building your project w/o strong names. 只需继续建立没有强名称的项目。 When you need to deploy it to Sharepoint, use a tool to sign it after it is built. 当您需要将其部署到Sharepoint时,请使用工具在构建后对其进行签名。 Here's a tool that does exactly that: 这是一个完全相同的工具:

http://signer.codeplex.com/Wikipage http://signer.codeplex.com/Wikipage

You can also do it manually, but it's a PITA: 您也可以手动完成,但它是PITA:

http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/ http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/

This is the OP but I don't have an OpenID login so I guess I can't reply as myself. 这是OP,但我没有OpenID登录,所以我想我不能像我一样回复。

Thanks for both the responses. 感谢您的回复。 I think either would have worked but the situation turned out to be a bit more complex. 我认为要么会有效,但情况会变得更复杂一些。 I've documented my findings here in case anyone else is interested. 我在这里记录了我的发现,以防其他人感兴趣。

In fact sharepoint references assembly A and assembly A in turn references assembly B. 事实上,sharepoint引用程序集A和程序集A依次引用程序集B.

I can build assembly A and B both unsigned with no problem, but then if I want to sign A, I have to change the project itself to reference the signed version of assembly B. 我可以在没有问题的情况下构建程序集A和B,但是如果我想签署A,我必须更改项目本身以引用程序集B的签名版本。

Although there might have been a way to do this, we decided the possible DLL conflicts and configuration control problems with having different sets of DLLs with the same name were not worth the hassle. 虽然可能有一种方法可以做到这一点,但我们认为可能的DLL冲突和配置控制问题与不同的具有相同名称的DLL集不值得麻烦。

So we have decided to sign both these assemblies in all builds, refactoring code into different assemblies where necessary to make sure that only the minimum amount of code is in the signed ones so they are less likely to change. 所以我们决定在所有版本中签署这两个程序集,在必要时将代码重构到不同的程序集中,以确保只有最少量的代码在签名的代码中,因此它们不太可能发生更改。

Tim 蒂姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM