当我尝试使用C#动态链接库在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中。
以下是ver 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.更新Mar-24-2021:可能是Npgsql https://github.com/npgsql/npgsql/issues/2677的错误
发布于 2021-03-24 11:49:53
显然,这可能是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>有关包的版本,请在项目参考中进行检查

发布于 2021-11-18 04:17:27
也有类似的问题。细节似乎很重要。除了上面的答案之外:
不知何故,Nuget创建了App.config文件,并将绑定重定向添加到Build Action设置为None的App.config,但有一个包含不同绑定重定向的CustomAction.config。在删除App.Config并将绑定重定向从它移动到CustomAction.config之后,它起作用了。值得一提的是,*.config文件的Build action应该设置为Content。Copy to output Directory - Do not Copy。
https://stackoverflow.com/questions/66757072
复制相似问题