2012-09-10 31 views
5

我正在努力the Autofac project試圖將我們所有的通用邏輯轉換爲Portable Class Libraries,併爲特定功能添加平臺特定的庫。如何在依賴於可移植類庫的庫上成功運行secannotate.exe?

我的開發機器是Windows 8 Enterprise(64位),我的VS 2012旗艦版安裝了所有的配件。我沒有安裝任何以前的.NET框架的東西,任何額外的工具,或任何額外的PCL特定的工具。 這是一個乾淨的,只有基本東西的新VM。一切構建和測試運行良好在這種配置。

當我試圖運行依賴於便攜式類庫中的一個.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
  • .NET的Windows Store應用程序

您可以通過創建複製問題一個新的/空的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
  • 系統2.0.5.0
  • System.ComponentModel.Composition 2.0.5.0
  • System.Core程序2.0.5.0

並再次,它只是一個PCL項目,而不是直接引用任何物品ING。字面意思 - 在.csproj文件中有不是單個參考線

如何解決此secannotate問題?有什麼額外的我需要安裝?有沒有我應該添加到secannotate命令行的參數?

回答

3

您需要將/ d開關,指着便攜式圖書館參考組件,例如:

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

記下你會得到解決混合桌面和CoreCLR mscorlib程序的警告,這可能是因爲被忽略儘管「便攜式」看起來像CoreCLR(Silverlight)以進行secannotate,但它並不是在.NET Framework的上下文中運行的。

+0

please fast =),我們不能在項目中使用PCL。在生產環境中,沒有辦法引用這個2.0.5.0框架程序集... – benwasd

+0

我已經更新了答案。 –

+0

這隻修復了開發機器上的驗證。沒有?在客戶端只有.NET 4.0安裝我的.NET 4.0目標PCL程序集仍然無法加載.. – benwasd

1

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

有一個清晰的方法可以讓你最終依賴它。如果你開始使用Autofac-2.6.3.862-Portable。zip下載,然後你會得到一個Autofac.dll版本確實有一個2.0.5.0 mscorlib依賴。有些事情,你可以用程序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項目。

+1

我以爲還必須有一箇舊的參考,但我已經檢查 - 沒有。這都是一個大的解決方案,所有的項目參考。三檢查。這就是爲什麼它讓我難倒了。 –

+0

我給這個問題增加了一些信息 - 我看到的程序集和引用的目標平臺出現了。 –