用于生成用于绑定重定向的 MVC 应用程序的配置 dll

本文关键字:用于 应用程序 配置 dll MVC 重定向 绑定 | 更新日期: 2023-09-27 18:32:30

我正在尝试解决我的 MVC 4 应用程序的绑定重定向问题:在配置(调试或发布(之间切换并编译我的代码后,我看到如下警告:

Consider app.config remapping of assembly "System.Web.Mvc, Culture=neutral, PublicKeyToken=31bf3856ad364e35" from Version "3.0.0.0" [...] to Version "4.0.0.0" [...] to solve conflict and get rid of warning.

我在 web.config 文件中有正确的映射,在 Web 应用程序中也有适当的引用。在web.config中,有以下重定向:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.15.0" newVersion="2.2.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

但是当我查看编译到 bin 文件夹并看到 MyWeb.dll.config 时,它看起来不同,它包含以下重定向:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.IO" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.3.0" newVersion="2.6.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.15.0" newVersion="2.2.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Extensions" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.15.0" newVersion="2.2.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.15.0" newVersion="2.2.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.WebRequest" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.15.0" newVersion="2.2.15.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.3.0" newVersion="2.6.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.3.0" newVersion="2.6.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这很奇怪,因为我找不到生成此文件的位置。下次构建后,MyWeb.dll.config 文件包含 web.config 的精确副本,在输出中我再也看不到警告了。但是每次更改配置或发布时,我都会看到此警告。我想确保我的 Web 应用程序正在定位到正确的 dll,但警告让我担心,我不知道如何解决它们。我尝试将 MyWeb.dll.config 添加到项目中并将其设置为始终复制,但它没有任何变化,文件像以前一样生成。

我已经使用AsmSpy检查第三方DLL以查找某些内容是否引用了不同版本的程序集,并尝试为每个此类文件添加适当的dll配置,但这也没有改变任何内容。

用于生成用于绑定重定向的 MVC 应用程序的配置 dll

我已经更新到 MVC 和 .NET Framework 4.5,现在看起来这个问题不再存在。

因此,要修复此错误,只需更新到最新版本即可。