首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查找未使用/不必要的assemblyBinding重定向

查找未使用/不必要的assemblyBinding重定向
EN

Stack Overflow用户
提问于 2018-04-26 07:05:37
回答 2查看 7.3K关注 0票数 19

在我们的web.config中,似乎有太多的绑定重定向,所以我要么:

  1. 看上去没必要
  2. 是用于在解决方案中任何地方都没有引用的程序集。

这只是绑定重定向的某些部分的示例:

代码语言:javascript
复制
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Azure.KeyVault.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.8.3.0" newVersion="5.8.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.8.3.0" newVersion="5.8.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.8.3.0" newVersion="5.8.3.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.1" newVersion="4.0.2.1" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
    <bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.2.4.0" newVersion="5.2.4.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.ApplicationInsights" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.5.1.0" newVersion="2.5.1.0" />
  </dependentAssembly>

我认为,在某个时候,Visual决定自动添加很多它们。

是否有一种方法来验证是否需要任何绑定重定向或自动验证/删除它们?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-31 11:23:31

解决这个问题的方法其实是非常简单和优雅的。

  1. 在Web.config /app.config中删除绑定重定向的所有
  2. 转到软件包管理器控制台
  3. 输入命令Add-BindingRedirect (还可以使用-ProjectName "SpecificProject"指定目标项目);
  4. 生成所有必要的绑定重定向;
  5. 运行您的应用程序,如果工作正常,请查看。如果没有,添加命令遗漏的任何缺少的绑定重定向。
票数 49
EN

Stack Overflow用户

发布于 2018-04-26 10:00:25

其中大多数是作为默认模板的一部分添加的。您可以根据应用程序中的yr需要,从绑定和项目引用中安全地删除其中的许多。这样,如果不小心将它们用作依赖项,您就会立即了解到。例如:-

  • "Microsoft.ApplicationInsights":审计应用
  • System.Web.Helpers: MVC的helpers
  • System.ValueTuple:元组作为数据结构,可以按名称访问每个属性
  • System.Threading.Tasks.Extensions: TPL扩展方法
  • Microsoft.SqlServer.Types:直接在应用程序代码中使用的SQL server中注册的数据类型
  • Microsoft.Owin.Security: Owin作为身份管理
  • Microsoft.Data.Edm:实体框架数据建模
  • Microsoft.Data.OData:开放数据服务

请注意,绑定重定向是在您的代码最初引用/请求一个旧版本而您正在提供一个较新版本时专门使用的。如果所使用的版本实际上与所提供的版本相同(主要用于主要框架组件(而不是NuGet提供的更新),则可以完全删除bindingRedirect部分。

为了安全起见,请注释掉每个部分,然后运行应用程序,如果不工作,可以取消对该部分的注释。

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50036791

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档