为什么AutogenerateBindingRedirects无法在Visual Studio 2017中用于Web.config [英] Why doesn't AutogenerateBindingRedirects work for a Web.config in Visual Studio 2017

查看:425
本文介绍了为什么AutogenerateBindingRedirects无法在Visual Studio 2017中用于Web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对需要Microsoft.AspNet.WebApi.Client 5.2.4的.Net Standard 2.0库进行了引用.这具有很多依赖关系,需要重定向才能使用较新的版本.

I have a reference to a .Net Standard 2.0 library that requires Microsoft.AspNet.WebApi.Client 5.2.4. This has a lot of dependencies that need to be redirected to use newer versions.

为了避免程序包/依赖关系爆炸,我已经更新了csproj文件中的第一个PropertyGroup:

To avoid package/dependency explosion I've updated the first PropertyGroup in the csproj file:

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

我期望使用AutoGenerateBindingRedirects来防止我需要更改Web.config以匹配添加的版本.

I'm expecting AutoGenerateBindingRedirects to prevent me from needing to change the Web.config to match the versions added.

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

Why do I still need to add binding redirects to my Web.config to resolve assembly conflicts?

推荐答案

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

Inspecting the output from the build shows that binding redirects are generated just not in the Web.config. Instead, they are in $(AssemblyName).dll.config. This file has the original configuration from Web.config as well as the binding redirects.

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

To put it all together you can have MSBuild copy the resulting config back to the Web.config. To do this you would add the following to the csproj:

<Target Name="AfterBuild">
  <Copy SourceFiles="$(TargetDir)\$(AssemblyName).dll.config" DestinationFiles="Web.config" />
</Target>

这篇关于为什么AutogenerateBindingRedirects无法在Visual Studio 2017中用于Web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆