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

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。

这些是版本 5.0.3 的依赖项:

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

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 应设置为 ContentCopy to output Directory - Do not Copy.