简体   繁体   English

从unsigned project引用的程序集需要强名称吗?

[英]Strong name required for assemblies referenced from unsigned project?

I'm working on a WCF service. 我正在开发一个WCF服务。 The WCF service interface and implementation are in separate projects. WCF服务接口和实现位于不同的项目中。 There's also a Windows service project to host the WCF service. 还有一个Windows服务项目来托管WCF服务。

One of the things the WCF service implementation needs to do is call out to several external ( SOAP ) web services. WCF服务实现需要做的一件事就是调用几个外部( SOAP )Web服务。 The way we typically structure this is we create a separate class library project for the SOAP service(s); 我们通常构建它的方式是为SOAP服务创建一个单独的类库项目; we'll create a Web reference and a factory/helper method in the class library. 我们将在类库中创建Web引用和工厂/帮助器方法。

The above detail may or may not be pertinent to the real problem. 以上细节可能与实际问题相关或不相关。 Which is that I get an error when building the WCF service implementation project (where X is one of the SOAP service wrapper assemblies): 这是我在构建WCF服务实现项目时遇到错误(其中X是SOAP服务包装程序集之一):

referenced assembly 'X' does not have a strong name 引用的程序集“X”没有强名称

But the WCF service implementation project isn't set to be signed (nor is the interface project). 但是WCF服务实现项目没有设置为签名(接口项目也不是)。 And at this point the only two things referencing it are the Windows service project and a unit test project -- and neither of those is signed either. 在这一点上,引用它的唯一两件事是Windows服务项目和单元测试项目 - 这两者都没有签名。

The WCF implementation also references other (pre-existing) web service wrapper projects, but it's only complaining about these two. WCF实现还引用了其他(预先存在的)Web服务包装器项目,但它只是抱怨这两个。 I've pulled up an existing and a new project file in a text editor side by side... And I can's see any significant differences. 我已经在文本编辑器中并排了一个现有的和一个新的项目文件......我可以看到任何重大的差异。

I've also checked whether any of the projects is importing a setting that requires it to be signed, as described in Stack Overflow question Remove signing from an assembly . 我还检查了是否有任何项目正在导入需要对其进行签名的设置,如Stack Overflow问题中所述从程序集中删除签名 That doesn't appear to be the case. 情况似乎并非如此。

I was attempting to use AutoMapper -- 1.1 since we're still on .NET 3.5 -- in my WCF implementation. 我试图使用AutoMapper - 1.1因为我们仍然在.NET 3.5上 - 在我的WCF实现中。 That is a signed assembly, so I can see where it might have a problem reflecting on my code and the SOAP service wrappers. 这是一个签名的程序集,所以我可以看到它可能在我的代码和SOAP服务包装器上出现问题。 But it seems to me that would be a run-time problem, not build time. 但在我看来,这将是一个运行时问题,而不是构建时间。 But because I suspected it might be at least a contributing factor, I removed AutoMapper and the dependent code but I still get the same error. 但是因为我怀疑它可能至少是一个促成因素,我删除了AutoMapper和相关代码,但我仍然得到相同的错误。

I have researched the issue, most of the search results consist of instructions on how to sign (possibly third-party) assemblies. 我已经研究过这个问题,大多数搜索结果都包含有关如何签名(可能是第三方)程序集的说明。

I've tried removing and re-adding the references, restarted Visual Studio and my PC. 我已经尝试删除并重新添加引用,重新启动Visual Studio和我的PC。

Visual Studio 2010 / .NET 3.5 on Windows 7 64-bit. Windows 7 64位上的Visual Studio 2010 / .NET 3.5。

I'm sure I'm missing something fairly obvious ... I just can't figure out what. 我敢肯定我错过了一些相当明显的东西......我只是想不出来。

Well ... this is embarrassing. 嗯......这很尴尬。

As I suspected, it was something simple. 我怀疑,这很简单。 The service interface and implementation were in fact set to be signed; 事实上,服务接口和实现已经签署; I was incorrect about that. 我对此不正确。 However, this was done not in the project settings/file, but in the AssemblyInfo.cs file, via the directive [assembly: AssemblyKeyFile("keyfile.snk")] . 但是,这不是在项目设置/文件中完成的,而是在AssemblyInfo.cs文件中,通过指令[assembly: AssemblyKeyFile("keyfile.snk")]

I was not familiar with this method of signing. 我不熟悉这种签名方法。 I gather it's been deprecated since VS2005 -- partially because it's more straightforward to manage signing via the project properties, partially because putting this information into the AssemblyInfo is considered a security risk. 我收集它自VS2005以来已被弃用 - 部分原因是通过项目属性管理签名更为直接,部分原因是将此信息放入AssemblyInfo被认为是安全风险。

And I had in fact looked at at least one of the AssemblyInfo files ... but apparently I didn't scroll down far enough. 事实上我至少看过一个AssemblyInfo文件......但显然我没有向下滚动得足够远。 (I said it was embarrassing.) (我这很尴尬。)

Hopefully someone else can benefit from this. 希望其他人可以从中受益。

You can not reference an unsigned assembly from a signed assembly, the project which fails to build should be the one that has a strong name key tied to it. 您无法从已签名的程序集中引用未签名的程序集,无法构建的项目应该是具有与之关联的强名称密钥的项目。

It is possible that you have a signed version of one of your references in the Global Assembly Cache that MSBuild is picking up instead of the reference you selected. 您可能在全局程序集缓存中有一个签名版本的MSBuild正在拾取而不是您选择的引用。

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

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