亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么visual studio為程序集重定向創建app.configs?

為什么visual studio為程序集重定向創建app.configs?

C#
慕容3067478 2021-09-19 15:33:08
我有一個包含大約 100 個項目的解決方案。我不知道究竟是什么觸發了它,但 Visual Studio 偶爾會向我的每個項目添加一個 app.config。它通??雌饋硐襁@樣:<?xml version="1.0" encoding="utf-8"?><configuration>  <runtime>    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      <dependentAssembly>        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />      </dependentAssembly>      <dependentAssembly>        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />        <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />      </dependentAssembly>    </assemblyBinding>  </runtime></configuration>據我所知,不需要這些 app.config 文件。如果我恢復所有這些更改并刪除 app.config 文件,一切似乎都正常。為什么 Visual Studio 這樣做,我怎樣才能讓它停止?
查看完整描述

1 回答

?
冉冉說

TA貢獻1877條經驗 獲得超1個贊

通常 VS 會在您更新 nuget 包時添加這些配置(綁定重定向)。它有助于防止 .NET 在尋找依賴項時出現一些問題,例如


  <dependentAssembly>

    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />

    <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />

  </dependentAssembly>

在此配置中,我們談到如果您的應用程序的其他一些依賴項引用了版本低于 11.0.0.0 的程序集,則它們應該使用版本 11.0.0.0。在這種情況下,如果您省略此綁定重定向,您將在運行時出現異常。


如果您的應用程序中沒有此類依賴項,則可以刪除這些配置。


查看完整回答
反對 回復 2021-09-19
  • 1 回答
  • 0 關注
  • 267 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號