【问题标题】:How can I successfully run secannotate.exe on a library that depends on a Portable Class Library?如何在依赖于可移植类库的库上成功运行 secannotate.exe?
【发布时间】:2012-09-10 22:52:54
【问题描述】:

我正在研究the Autofac project,试图将我们所有的通用逻辑转换为Portable Class Libraries,并为特定功能添加特定于平台的库。

我的开发机器是 Windows 8 Enterprise(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
  • 银光 5
  • .NET 用于 Windows 应用商店应用

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

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

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

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

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

我该如何解决这个 secannotate 问题?我需要安装什么额外的东西吗?我应该在 secannotate 命令行中添加一个参数吗?

【问题讨论】:

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


    【解决方案1】:

    你需要传递 /d 开关,指向 Portable Library 引用程序集,例如:

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

    请注意,您将收到有关混合桌面和 CoreCLR mscorlib 的警告,这可以忽略,因为虽然“便携式”看起来像 CoreCLR (Silverlight) 进行分割,但它不是在 .NET Framework 的上下文中运行时。

    【讨论】:

    • 请快点 =),我们不能在项目中使用 PCL。在生产环境中无法引用这个 2.0.5.0 框架程序集...
    • 这仅修复了开发机器上的验证。不?在客户端上只安装了 .NET 4.0 我的 .NET 4.0 目标 PCL 程序集仍然无法加载..
    • 这个答案是关于 SecAnnotate。如果 PCL 程序集无法在 4.0 上加载,则说明您没有安装 microsoft.com/en-us/download/details.aspx?id=3556。请参阅此页面上的“部署 .NET Framework 应用程序”部分:msdn.microsoft.com/en-us/library/gg597391.aspx
    • @DavidKean 抱歉,我错过了您的更新。由于某种原因,它没有出现在我的 SO 收件箱中。这完美地工作。谢谢!!!
    【解决方案2】:

    在 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 项目。

    【讨论】:

    • 我认为也一定有一个旧的参考,但我已经检查过 - 没有。这一切都在一个大解决方案中,所有项目参考。三重检查。这就是为什么它让我难住了。
    • 我在问题中添加了更多信息 - 我看到的程序集和参考的目标平台出现。
    猜你喜欢
    • 1970-01-01
    • 2017-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-21
    • 2013-10-25
    • 1970-01-01
    相关资源
    最近更新 更多