问题描述
我正在寻找一种方法来避免需要在 app.config 文件中添加dependentAssembly。 实际的相关项目是一个应该添加到全局流程的库。无法修改全局进程(.net Framework)的app.config。
问题示例:
1.将 nuget 包 Application Insights 添加到我的控制台应用程序时 => 它不会在我的 app.config 中添加“dependentAssembly”部分。应用洞察库在进行测试时也能正常工作。
2.在添加 nuget 包 Serilog 和 Serilog Application Insights 时,它会在 app.config 文件中添加一个新的“dependentAssembly”部分。这个也很好用。
但是,在删除与应用程序洞察相关的“dependentAssembly”部分时,会出现以下错误:
无法加载文件或程序集“Microsoft.ApplicationInsights, 版本=2.12.0.21496,文化=中性, PublicKeyToken=31bf3856ad364e35' 或其依赖项之一。这 定位的程序集的清单定义与程序集不匹配 参考。 (来自 HRESULT 的异常:0x80131040)
==> 这不是唯一存在此类问题的 serilog 插件。 配置生成器还包括 app.config 中的“dependentAssembly”部分。
可以在此处找到 appconfig 示例:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.16.0.18277" newVersion="2.16.0.18277" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
错误消息通知它正在寻找 Version=2.12.0.21496 而我正在使用应用程序洞察的 2.16 版。这可以通过安装 v2.12.. 来解决,但我不想依赖它,因为它可能因每个服务器而异。
还有其他方法可以定义版本号吗?
先谢谢你!
亲切的问候, 库尔特
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)