簡體   English   中英

使用.net 4.0編寫的程序,但我需要此應用程序在運行.net 2.0的計算機上運行

[英]Program written using .net 4.0 but I need this application to run on computers running .net 2.0

這個問題應該從其標題中清楚地說明,但讓我更詳細地解釋一下。 我剛剛完成了我的應用程序的編寫,我認為是.Net 4.0框架(見下圖)。 在意識到我需要我的應用程序與最早版本的.Net框架兼容之后,我回過頭來改變了Visual Studio的Properties窗口中的Target Framework。 不幸的是,這樣做給我留下了一長串警告 - 以及一個嚴重的錯誤。 我很好奇是否有人有一些解決方案可以讓我的應用程序(使用.Net 4.0框架編寫)在運行.Net 2.0框架的環境中運行。

原始編譯

在.Net 4.0 Framework中編譯的證明

錯誤列表:

.Net 2.0錯誤 謝謝,埃文

編輯:

我知道第二張圖片對於我們大多數人來說並不完全可見,所以我將在下面發布錯誤:

Warning 9   The referenced component 'System.Xml.Linq' could not be found.  
Warning 10  The referenced component 'System.Data.DataSetExtensions' could not be found.    
Warning 8   The referenced component 'System.Core' could not be found.  
Warning 11  The referenced component 'Microsoft.CSharp' could not be found.     
Warning 4   The primary reference "System.Xml.Linq", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Xml.Linq" or retarget your application to a framework version which contains "System.Xml.Linq".   Protection
Warning 2   The primary reference "System.Xml.Linq" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Xml.Linq" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".   Protection
Warning 5   The primary reference "System.Data.DataSetExtensions", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Data.DataSetExtensions" or retarget your application to a framework version which contains "System.Data.DataSetExtensions". Protection
Warning 3   The primary reference "System.Data.DataSetExtensions" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Data.DataSetExtensions" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".   Protection
Warning 1   The primary reference "System.Core", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "System.Core" or retarget your application to a framework version which contains "System.Core".   Protection
Warning 6   The primary reference "Microsoft.CSharp", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "Microsoft.CSharp" or retarget your application to a framework version which contains "Microsoft.CSharp".    Protection
Error   7   Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Line 123, position 5.    C:\Users\FARINA_EVAN\Documents\Programming\C#\Run Time Crypter\Run Time Crypter\Properties\Resources.resx   123 5   Protection

當您創建面向.NET 4.0的新項目時,Visual Studio會自動添加對一些常用的.NET 4.0程序集的引用。 但是,在查找目標平台時,這些引用不會被刪除,因此需要手動刪除,因為您無法從.NET 2.0應用程序引用.NET 4.0程序集。

所以首先刪除這些錯誤的引用,看看是否還有錯誤。 如果您使用了.NET 2.0中不可用的任何.NET功能,則可能需要更改某些源代碼,或者如果缺少.NET 2.0程序集,則可能需要添加新的引用。

出現的任何編譯器錯誤都可能指向正確的方向。

是的,但您需要刪除任何引用大於2的.net版本的代碼。要清除上述錯誤,您需要刪除對所有項目的引用,其中包含“找不到引用的組件xx” ”。 此外,您還需要搜索資源,配置等文件,以將.net 2 - >的任何.net 4引用從4.0.0.0替換為2.0.0.0,或者如果它們不存在則完全刪除引用。網2。

錯誤消息告訴您出現了什么問題,在這種情況下,您的項目中有無法解析的引用。 展開項目樹中的references節點,並刪除帶有警告圖標的引用。

如果您在此之后嘗試編譯,則可能會收到有關您使用的.NET 2.0中不可用的類,命名空間或關鍵字的其他錯誤。 您必須刪除它們或更改您的代碼。

由於Linq在.NET 2.0中不可用,因此您可以嘗試使用LinqBridge作為替代品。

暫無
暫無

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

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