C# 使用PostSharp Toolkit构建在4.5.1上失败,但可在4.5上使用

C# 使用PostSharp Toolkit构建在4.5.1上失败,但可在4.5上使用,c#,postsharp,C#,Postsharp,我保留了PostSharp.Toolkit.Threading的NuGet包,版本为2.1.1.12,因为我无法升级到版本3.x。只要我继续使用.Net 4或4.5,任何项目都可以编译,但一旦我更改为4.5.1或4.5.2,就会出现以下错误: Error 3 error: Unhandled exception (2.1.7.35, 32 bit, CLR 2.0, Release): Cannot load assembly T:\WindowsFormsApplication4\pa

我保留了PostSharp.Toolkit.Threading的NuGet包,版本为2.1.1.12,因为我无法升级到版本3.x。只要我继续使用.Net 4或4.5,任何项目都可以编译,但一旦我更改为4.5.1或4.5.2,就会出现以下错误:

Error   3   error: Unhandled exception (2.1.7.35, 32 bit, CLR 2.0, Release): Cannot load assembly T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll.
============ PostSharp Assembly Loading Log ===================
LOG:    NativeDotNetPlatform.LoadAssemblyFromFile: T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll.
LOG:    Assembly identity returned by the host: postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil.
LOG:    Assembly 'postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil' is not yet loaded in the AppDomain.
LOG:    Invoking Assembly.Load({postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil})
LOG:    (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil".
LOG:    Finding the assembly with binding identity 'postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil'.
LOG:    Location found from cache: 'T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll'.
LOG:    (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil": assembly found in search path.
LOG:    (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil": located in "T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll".
LOG:    (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil": returned successfully.
LOG:    AssemblyLoadException: Could not load file or assembly 'postsharp.toolkit.threading.weaver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
LOG:    Loaded: 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll'.
LOG:    Loaded: 'PostSharp.Hosting, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Hosting.dll'.
LOG:    Loaded: 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'.
LOG:    Loaded: 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'.
LOG:    Loaded: 'PostSharp.Sdk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Sdk.dll'.
LOG:    Loaded: 'PostSharp.Settings, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Settings.dll'.
LOG:    Loaded: 'PostSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.dll'.
LOG:    Loaded: 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'.
LOG:    Loaded: 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' from 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'.
LOG:    Loaded: 'PostSharp.Pipe, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Pipe.dll'.
LOG:    Loaded: 'PostSharp.Sdk.XmlSerializers, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Sdk.XmlSerializers.dll'.
=============================================================== See below for details.  T:\WindowsFormsApplication4\WindowsFormsApplication4\POSTSHARP  WindowsFormsApplication4

我不明白为什么会这样。有没有什么专家?

日志显示PostSharp托管的CLR版本是2.0。在加载threading weaver程序集时,CLR还尝试加载一些需要CLR 4.0的依赖项。这是当你得到一个例外

PostSharp 2.x可以识别目标framework 4.5并自动选择托管CLR 4.0,但无法识别较新的framework 4.5.1版本,默认情况下使用CLR 2.0


您可以通过将MSBuild属性
PostSharpTargetFrameworkVersion
设置为4.0来覆盖宿主CLR。

日志显示PostSharp宿主CLR版本为2.0。在加载threading weaver程序集时,CLR还尝试加载一些需要CLR 4.0的依赖项。这是当你得到一个例外

PostSharp 2.x可以识别目标framework 4.5并自动选择托管CLR 4.0,但无法识别较新的framework 4.5.1版本,默认情况下使用CLR 2.0

通过将MSBuild属性
PostSharpTargetFrameworkVersion
设置为4.0,可以覆盖宿主CLR