我有一個(gè)包含大約 100 個(gè)項(xiàng)目的解決方案。我不知道究竟是什么觸發(fā)了它,但 Visual Studio 偶爾會(huì)向我的每個(gè)項(xiàng)目添加一個(gè) app.config。它通??雌饋?lái)像這樣:<?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>據(jù)我所知,不需要這些 app.config 文件。如果我恢復(fù)所有這些更改并刪除 app.config 文件,一切似乎都正常。為什么 Visual Studio 這樣做,我怎樣才能讓它停止?
1 回答

冉冉說(shuō)
TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個(gè)贊
通常 VS 會(huì)在您更新 nuget 包時(shí)添加這些配置(綁定重定向)。它有助于防止 .NET 在尋找依賴項(xiàng)時(shí)出現(xiàn)一些問(wèn)題,例如
<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>
在此配置中,我們談到如果您的應(yīng)用程序的其他一些依賴項(xiàng)引用了版本低于 11.0.0.0 的程序集,則它們應(yīng)該使用版本 11.0.0.0。在這種情況下,如果您省略此綁定重定向,您將在運(yùn)行時(shí)出現(xiàn)異常。
如果您的應(yīng)用程序中沒(méi)有此類依賴項(xiàng),則可以刪除這些配置。
- 1 回答
- 0 關(guān)注
- 234 瀏覽
添加回答
舉報(bào)
0/150
提交
取消