[英]Add custom action in Wix with multiple dependencies
我在嘗試使用 C# DLL 在 Wix 中添加自定義操作時遇到問題。 我有一個自定義操作來檢查 Postgresql 服務器連接,在 C# 項目中,我使用Npgsql
來檢查它。 Npgsql
ver 3.1.0
一切正常。 但是當我將Npgsql
升級到5.0.3
版(最新版)時,再次構建 MSI 安裝程序,點擊按鈕運行自定義操作,發生錯誤
Could not load file or assembly 'System.Threading.Tasks.Extensions'
我知道新版本需要System.Threading.Tasks.Extensions
。 但我不知道如何嵌入到我的自定義操作 DLL 中。
已更新,這是發生錯誤時的完整日志
System.IO.FileLoadException: Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
at Npgsql.ConnectorPool..ctor(NpgsqlConnectionStringBuilder settings, String connString)
at Npgsql.NpgsqlConnection.GetPoolAndSettings()
at Npgsql.NpgsqlConnection.set_ConnectionString(String value)
at Npgsql.NpgsqlConnection..ctor(String connectionString)
at OmsCustomAction.OmsCustomActions.TestConnection(PGInfo pgServer, String& error) in C:\OPSWAT\sf-core\wix-setup\OmsCustomAction\OmsCustomAction\OmsCustomAction.cs:line 263
=== Pre-bind state information ===
LOG: DisplayName = System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
(Fully-specified)
LOG: Appbase = file:///C:/Users/eckkom/AppData/Local/Temp/MSI7CB0.tmp-
LOG: Initial PrivatePath = NULL
Calling assembly : System.Threading.Channels, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\eckkom\AppData\Local\Temp\MSI7CB0.tmp-\CustomAction.config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Threading.Tasks.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
LOG: Attempting download of new URL file:///C:/Users/eckkom/AppData/Local/Temp/MSI7CB0.tmp-/System.Threading.Tasks.Extensions.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Revision Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
2021 年 3 月 24 日更新:可能是Npgsql
https://github.com/npgsql/npgsql/issues/2677的錯誤
顯然,這可能是Npgsql
的錯誤: https://github.com/npgsql/npgsql/issues/2677
但我終於找到了解決這個問題的方法。 只需創建一個配置文件app.config
或像這樣修改現有的.config
文件
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.1" newVersion="5.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Channels" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>
有類似的問題。 細節似乎很重要。 除了上面的答案:
不知何故,Nuget 創建了App.config
文件並將綁定重定向添加到App.config
並將Build Action
設置為None
,但是有一個CustomAction.config
包含不同的綁定重定向。 在刪除 App.Config 並將綁定重定向從它移動到CustomAction.config
之后,它起作用了。 同樣重要的是要提到*.config
文件的Build action
應設置為Content
。 Copy to output Directory
- Do not Copy
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.