簡體   English   中英

將.net 4.5應用程序降級到4.0

[英]downgrade .net 4.5 application to 4.0

我想將.net庫從框架版本4.5降級到.net 4.0。

我使用nuget安裝了幾個庫:

  • Microsoft.AspNet.WebApi.Client及其依賴項:
  • Newtonsoft.Json
  • System.Net.Http(Microsoft .Net 4 HTTP客戶端庫)

我做以下事情

  • 在我的解決方案中的每個項目的設置中,我將目標框架設置為4.0 在它之后我嘗試重建我的解決方案但當然沒有成功因為錯誤The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?) ,HTTP Client libs也是如此

  • 使用nuget ui manager我刪除了依賴項並嘗試重新安裝 但是有一個錯誤Could not install package 'Microsoft.AspNet.WebApi.Client 5.1.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. Could not install package 'Microsoft.AspNet.WebApi.Client 5.1.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

我的問題是:我可以降級這個項目,還是應該用一些支持.net 4替換這些庫並重寫代碼的某些部分?

.NET 4.5是.NET 4.0的就地升級,這意味着CLR是相同的,但添加了新的庫以及錯誤修復和性能改進,並且兩者都指向.NET CLR 4。

在您的情況下,由於已經安裝了.NET 4.5,因此4.5更新完全取代了.NET 4.0運行時。

即使您將項目更改為.NET 4.0,內部使用的庫仍然指向4.5但僅限於可用於4.0的庫,但行為可能與您在純.NET 4中的預期不同。

因此,為了將您的項目從4.5降級到4.0,我同意您的意見,您需要:

  1. 僅將.NET框架重新安裝到.NET 4(如果不再需要.NET 4.5)
  2. 將項目更改為指向.NET 4
  3. 重寫.NET 4不支持的部分代碼(例如,在您的情況下,Microsoft.AspNet.WebApi.Client 5.1.1隨.NET 4.5中的WebApi2一起提供,您需要將其降級為使用方式如.NET 4所提供的)

漢塞爾曼瑞克解釋得非常好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM