我有一個天藍色的雲項目和一個工人角色項目(+一些輔助項目)的解決方案。 當我在本地調試的工人,我得到這個異常:nuget的程序集由GAC的程序集覆蓋
無法加載文件或程序集「System.Runtime.Extensions,版本= 4.0.0.0,文化=中性公鑰= b03f5f7f11d50a3a」或之一其依賴。定位的程序集清單定義與程序集引用不匹配。 (從HRESULT異常:0x80131040) 「:」 System.Runtime.Extensions,版本= 4.0.0.0,文化=中性公鑰= b03f5f7f11d50a3a
FusionLog:
=== Pre-bind state information ===
LOG: DisplayName = System.Runtime.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Azure/roles/[worker project]/approot
LOG: Initial PrivatePath = C:\Azure\roles\[worker project]\approot
Calling assembly : Microsoft.Extensions.Configuration, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Azure\roles\[worker project]\approot\[worker assembly].dll.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
LOG: Post-policy reference: System.Runtime.Extensions, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: Attempting download of new URL file:///C:/Azure/roles/[worker project]/approot/System.Runtime.Extensions.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
我在建輸出中看到什麼:
2> Task "Message"
2> CopyLocalDependencies=[solution]\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll
2> Task "Message"
2> CopyLocalDependencies=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.Extensions.dll
...
2> Task "Message"
2> WorkerFiles=[solution]\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll -> System.Runtime.Extensions.dll
2> Task "Message"
2> WorkerFiles=C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.Extensions.dll -> System.Runtime.Extensions.dll
...
2> Copying file from "[solution]\packages\System.Runtime.Extensions.4.3.0\lib\net462\System.Runtime.Extensions.dll" to "[solution]\[azure project]\obj\Debug\[worker project]\System.Runtime.Extensions.dll".
2> Copying file from "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.2\Facades\System.Runtime.Extensions.dll" to "[solution]\[azure project]\obj\Debug\[worker project]\System.Runtime.Extensions.dll".
爲什麼MSBuild將GAC的程序集複製到本地文件夾?如何改變這種行爲?我沒有直接參考GAC的System.Runtime.Extensions。 或如何更改複製程序集的順序?
我的嘗試:
- 添加屬性的工人項目DoNotCopyLocalIfInGac =真
- 添加一個直接引用NuGet包System.Runtime.Extensions
UPD 發現類似問題
- https://github.com/Azure/service-fabric-issues/issues/54
- https://github.com/Azure/azure-sdk-for-net/issues/2363
看起來你已經破解它,你放棄了之前嚴重,需要猜測。我假設你最好從app.config文件中移除BindingRedirect,以強制4.1.1.0被加載以正常化這一點。在程序集引用上覆制Local = true也需要重置。這是一個可重定位的程序集,它應該從GAC加載4.0.0.0。 –
@HansPassant它幫助,但我恐怕有一天或其他我會因爲舊的程序集而得到異常「System.MissingMethodException:Method not found ...」。一些nuget軟件包依賴於System.Runtime.Extensions軟件包。同樣刪除bindingRedirects(默認情況下會自動添加)是很費力的,因爲我必須逐個刪除重定向 - 其他一些重定向是必需的,因爲nuget程序集已在Approot文件夾中正確複製。 –
我需要一種方法來停止複製GAC的組件或設置複製順序(首先來自GAC,然後是來自軟件包)。 –