在具有多个依赖项的 Wix 中添加自定义操作

问题描述

我在尝试使用 C# DLL 在 Wix 中添加自定义操作时遇到问题。 我有一个用于检查 Postgresql 服务器连接的自定义操作,在 C# 项目中,我使用 Npgsql 进行检查。 Npgsql 版本 3.1.0 一切正常。 但是当我将 Npgsql 升级到 ver 5.0.3(最新版本)时,再次构建 MSI 安装程序,点击按钮运行自定义操作,发生错误

Could not load file or assembly 'System.Threading.Tasks.Extensions'

我知道新版本需要 System.Threading.Tasks.Extensions。 但我不知道如何嵌入到我的自定义操作 DLL 中。

这些是版本 5.0.3 的依赖项:

enter image description here

更新,这是发生错误时的完整日志

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,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,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,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,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一个bug 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>

对于包的版本,请在您的项目参考中查看 enter image description here