简体   繁体   English

需要一个C#程序集来松散地引用一个强命名的程序集

[英]Need a C# Assembly to reference a strongly named assembly loosely

So here's the problem. 所以这就是问题所在。 I'm writing some StyleCop plug-in assemblies for use at the company I work for. 我正在写一些StyleCop插件组件,供我工作的公司使用。 As such, these assemblies need to reference Microsoft.StyleCop.CSharp.dll for example, which is strongly named. 因此,这些程序集需要引用Microsoft.StyleCop.CSharp.dll,例如强名称。

The problem comes in that if I build this and pass it along to the developers in my group, they must have the same version of the StyleCop dll (currently 4.3.3.0) or it fails to load. 问题在于,如果我构建它并将其传递给我的组中的开发人员,则它们必须具有相同版本的StyleCop dll(当前为4.3.3.0)或者无法加载。

What is the best way to make my add-on rules DLL more independent? 使我的附加规则DLL更独立的最佳方法是什么? Should I just install my 4.3.3.0 version of those subordinate StyleCop dlls in the GAC? 我应该在GAC中安装我的4.3.3.0版本的那些从属StyleCop dll吗? Can an assembly (vs an application) use a policy file? 程序集(与应用程序)可以使用策略文件吗?

Oh, and one of the main problems is i would like it to work with ANY version of StyleCop the client has installed (or at least 4.3.3.0 or later) if possible. 哦,其中一个主要问题是我希望它可以与客户安装的任何版本的StyleCop(或至少4.3.3.0或更高版本)一起使用。

Many thanks in advance. 提前谢谢了。

Yes you should just install the same version for the other developers. 是的,您应该为其他开发人员安装相同的版本。 If you do not, you may have unpredictable runtime failures due to changes within StyleCop. 如果不这样做,由于StyleCop中的更改,您可能会遇到不可预测的运行时故障。 Presumably that is why they bothered to increment the version number. 据推测,这就是他们为增加版本号而烦恼的原因。

If you don't want to do this, you can configure a different assembly binding in the app.config file. 如果您不想这样做,可以在app.config文件中配置不同的程序集绑定。 In the config the actual version number which you intend to use at runtime is needed. 在配置中,您需要在运行时使用的实际版本号。 And yes, this can even be done via policy. 是的,这甚至可以通过政策来完成。 But again, I think you are better served by including the correct DLL in the first place. 但同样,我认为首先包含正确的DLL会更好。

In your project, go to the properties on the StyleCop reference. 在项目中,转到StyleCop参考上的属性。 Try setting the "Specific Version" property to false. 尝试将“特定版本”属性设置为false。

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

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