【问题标题】:Asp core wrong assembly redirect on publish发布时 Asp 核心错误的程序集重定向
【发布时间】:2016-09-13 09:13:23
【问题描述】:

使用 Visual Studio 发布我的 asp 核心项目时,会在我的可执行文件旁边创建一个 .config 文件。

.config 包括几个bindingRedirect,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
        <bindingRedirect oldVersion="6.0.0.0" newVersion="8.0.0.0" />
        <bindingRedirect oldVersion="7.0.0.0" newVersion="8.0.0.0" />
        <bindingRedirect oldVersion="6.0.0.0" newVersion="9.0.0.0" />
        <bindingRedirect oldVersion="8.0.0.0" newVersion="9.0.0.0" />
        <bindingRedirect oldVersion="7.0.0.0" newVersion="9.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Serilog" publicKeyToken="24c2f752a8e58a10" culture="neutral" />
        <bindingRedirect oldVersion="1.5.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="1.1.37.0" newVersion="1.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Reflection.Metadata" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="1.2.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这里我想将bindingRedirectNewtonsoft.Json 改为:

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
  <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>

根据这篇博文:http://blog.rytmis.net/2016/03/29/asp-net-core-and-assembly-binding-redirects/ 我应该能够创建一个App.config 并在那里指定绑定。但是,我无法让它工作。当我添加一个时,它仍然会产生相同的.config

有什么想法吗?

注意:我可以在我的项目中创建一个.config 文件,该文件与我的可执行文件同名并使用正确的bindingRedirect,然后在我的project.json 文件中编辑publishOptions包括它。然后我必须手动添加所有其他未来的bindingredirect

【问题讨论】:

    标签: asp.net-core dotnet-cli assembly-binding-redirect


    【解决方案1】:

    您需要创建一个 web.config 转换文件。

    这个答案会派上用场,因为自己添加并不容易 - https://stackoverflow.com/a/16826106/1147920

    您也可以手动执行此操作,方法是创建 web.config 文件的副本并将其重命名为 web.release.config 或 web.{PublishProfile}.config(如果您正在使用)。

    要编写转换规则来编辑 bindingRedirect 参考官方文档 - https://docs.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 2020-05-14
      • 1970-01-01
      • 1970-01-01
      • 2019-08-01
      • 2017-04-09
      • 2016-11-18
      相关资源
      最近更新 更多