如何在依赖于可移植类库的库上成功运行secannotate.exe?

时间:2012-09-10 22:52:54

标签: .net code-access-security portable-class-library

我正致力于the Autofac project尝试将所有常用逻辑转换为Portable Class Libraries并为特定功能添加特定于平台的库。

我的开发机器是Windows 8企业版(64位),我安装了VS 2012 Ultimate以及所有装饰。我没有安装任何以前的.NET框架,任何其他工具或任何额外的PCL专用工具。 这是一个干净的,新的虚拟机,只有基本的东西。在此配置中,所有构建和测试运行良好。

当我尝试在依赖于其中一个可移植类库的.NET 4.5(完整配置文件)库上运行secannotate.exe时,我收到一条错误,指示我需要mscorlib 2.0.5.0

这是一个示例错误。 PCL是Autofac.dll; .NET 4.5完整配置文件库是Autofac.Configuration.dll。

Error running annotator: Could not find referenced assembly 'Assembly(Name=mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)'. Ensure that the reference paths and assemblies are setup correctly.
Microsoft (R) .NET Framework Security Transparency Annotator 4.0.30319.17929
Copyright (C) Microsoft Corporation.  All rights reserved.

Loaded assembly 'Autofac.Configuration' from 'C:\dev\opensource\autofac\trunk\build_output\bin\net40\Autofac.Configuration.dll'.
Resolving assembly 'Assembly(Name=mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089)'.
Loaded assembly 'mscorlib' from 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
Loaded referenced assembly from 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
Using core assembly: 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.
Assembly 'Autofac.Configuration' is using transparency model 'Level 2'.
Assembly 'mscorlib' is using transparency model 'Level 2'.
Loaded assembly 'Autofac' from 'C:\dev\opensource\autofac\trunk\build_output\bin\net40\Autofac.dll'.
Resolving assembly 'Assembly(Name=mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)'.
   at Microsoft.Security.Tools.CciHostEnvironment.ResolvingAssemblyReference(IUnit referringUnit, AssemblyIdentity referencedAssembly)
   at Microsoft.Security.Tools.CciHostEnvironment.LoadCoreAssembly()
   at Microsoft.Security.Tools.CciHostEnvironment..ctor(ISecAnnotateHost host, String rootAssemblyPath)
   at Microsoft.Security.Tools.SecAnnotate.LoadInputAssemblies()
   at Microsoft.Security.Tools.SecAnnotate.AnnotateAssemblies()
   at Microsoft.Security.Tools.SecAnnotate.Main(String[] args)

Autofac便携式类库目标:

  • .NET 4.0
  • Silverlight 5
  • 适用于Windows应用商店应用的.NET

您可以通过创建针对这些内容并构建它的新/空PCL来复制该问题。你会看到它引用了mscorlib 2.0.5.0。

有些搜索让我相信这是对旧Silverlight汇编版本的引用,但是PCL项目没有特定的版本引用,所以我只能想象这是由VS 2012 PCL工具引入的。其他人似乎通过安装在VS 2012之前发布的.NET框架更新来解决类似的问题。我无法在我的机器上的任何地方找到mscorlib 2.0.5.0。

在我构建的Autofac.dll程序集中查看dotPeek,我看到它引用:

  • mscorlib 2.0.5.0
  • System 2.0.5.0
  • System.ComponentModel.Composition 2.0.5.0
  • System.Core 2.0.5.0

而且,它只是一个PCL项目,而不是直接引用任何东西。从字面上看 - .csproj文件中没有一条参考线

如何解决此注释问题?我还需要安装其他内容吗?我应该在secannotate命令行中添加一个参数吗?

2 个答案:

答案 0 :(得分:3)

您需要传递/ d开关,指向可移植库引用程序集,例如:

secannotate /v "Autofac.Configuration.dll" /d:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0"

请注意,您将收到有关混合桌面和CoreCLR mscorlib的警告,这可以忽略,因为虽然“可移植”看起来像CoreCLR(Silverlight)来进行限制,但它不是在.NET Framework环境下运行时。

答案 1 :(得分:1)

在VS2012之前的早期版本的PCL中引用了Mscorlib版本2.0.5.0。

有一个明确的方法可以让你最终依赖它。如果您开始使用Autofac-2.6.3.862-Portable.zip下载,那么您将获得一个确实具有2.0.5.0 mscorlib依赖关系的Autofac.dll版本。你可以用ildasm.exe看到的东西,双击清单:

// Metadata version: v4.0.30319
.assembly extern retargetable mscorlib
{
  .publickeytoken = (7C EC 85 D7 BE A7 79 8E )                         // |.....y.
  .ver 2:0:5:0
}
.assembly extern retargetable System.Core
{
  .publickeytoken = (7C EC 85 D7 BE A7 79 8E )                         // |.....y.
  .ver 2:0:5:0
}
// etc..

所以,以某种方式,你的Autofac.Configuration.dll是从引用该版本的Autofac.dll而不是你构建的版本的项目构建的。从项目中删除该引用。使用Project + Add Reference并使用Project选项卡,勾选Autofac项目。