为什么 AutogenerateBindingRedirects 不适用于 Visual Studio 2017 中的 Web.config

2023-12-30

我引用了需要 Microsoft.AspNet.WebApi.Client 5.2.4 的 .Net Standard 2.0 库。这有很多依赖项需要重定向才能使用较新的版本。

为了避免包/依赖项爆炸,我更新了 csproj 文件中的第一个 PropertyGroup:

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

我希望 AutoGenerateBindingRedirects 能够阻止我更改 Web.config 以匹配添加的版本。

为什么我仍然需要向 Web.config 添加绑定重定向来解决程序集冲突?


看来 AutoGenerateBindingRedirects 不适用于 Web 项目https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection.

检查构建的输出表明绑定重定向不是在 Web.config 中生成的。相反,它们位于 $(AssemblyName).dll.config 中。该文件具有 Web.config 的原始配置以及绑定重定向。

为了将它们放在一起,您可以让 MSBuild 将生成的配置复制回 Web.config。为此,您需要将以下内容添加到 csproj 中:

<Target Name="AfterBuild">
  <Copy SourceFiles="$(TargetDir)\$(AssemblyName).dll.config" DestinationFiles="Web.config" />
</Target>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为什么 AutogenerateBindingRedirects 不适用于 Visual Studio 2017 中的 Web.config 的相关文章

随机推荐