我有一个 .Net Standard 2.0 库的引用,它需要 Microsoft.AspNet.WebApi.Client 5.2.4。这有很多依赖项需要重定向才能使用更新的版本。
为了避免包/依赖项爆炸,我更新了 csproj 文件中的第一个 PropertyGroup:
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
我期望 AutoGenerateBindingRedirects 可以防止我需要更改 Web.config 以匹配添加的版本。
为什么我仍然需要向我的 Web.config 添加绑定(bind)重定向来解决程序集冲突?
最佳答案
根据 https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection,AutoGenerateBindingRedirects 似乎不适用于 Web 项目.
检查构建的输出表明绑定(bind)重定向只是不在 Web.config 中生成。相反,它们位于 $(AssemblyName).dll.config 中。此文件具有来自 Web.config 的原始配置以及绑定(bind)重定向。
要将它们放在一起,您可以让 MSBuild 将生成的配置复制回 Web.config。为此,您需要将以下内容添加到 csproj:
<Target Name="AfterBuild">
<Copy SourceFiles="$(TargetDir)\$(AssemblyName).dll.config" DestinationFiles="Web.config" />
</Target>
关于c# - 为什么 AutogenerateBindingRedirects 不适用于 Visual Studio 2017 中的 Web.config,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48970018/