C# vs2010 .net framework 4 工程转 vs2005工程 .net framework2 (一)

来源:互联网 发布:淘宝网怎么找厂家店 编辑:程序博客网 时间:2024/06/03 12:58

当前正在做的一个项目,原来使用vs2010 .net framework4.0 C#做的界面,但是最近客户要求支持windows 2000 server。顿时大家都傻眼了。没办法,客户是大爷呀。在网上搜了半天,只发现哭爹喊娘要方法的,没看到什么好的解决办法。还是自己动手吧。整个过程可以说是一波三折。

首先尝试的方法是把vs2010工程的Target framework设置成.net framework2.0;编译通过但是不能运行;

接着把上面的工程修改成2005工程;编译通过但还是不能运行;

最后在windows2000下安装vs2005,调试运行,发现最后问题之所在,最终完成程序的迁移。

为了方便弟兄们检索,文中列出了详细的编译错误。另外上述三步放到三篇文章里面,方便阅读。

 

最初想法:windows 2000 不是支持.net framework2.0吗,把当前工程的目标Target framework设置成.net framework2.0不就行了吗。以下简述修改过程:

1 重新编译,错误如下:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: 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".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: 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".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: 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".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: The primary reference "System.Runtime.Serialization", 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.Runtime.Serialization" or retarget your application to a framework version which contains "System.Runtime.Serialization".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "System.ServiceModel" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime.Serialization, Version=3.0.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.ServiceModel" or retarget your application to a framework version which contains "System.Runtime.Serialization, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: The primary reference "System.ServiceModel", 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.ServiceModel" or retarget your application to a framework version which contains "System.ServiceModel".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: 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".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: 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".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3267: 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".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "System.ServiceModel" could not be resolved because it has an indirect dependency on the framework assembly "System.IdentityModel, Version=3.0.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.ServiceModel" or retarget your application to a framework version which contains "System.IdentityModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "System.ServiceModel" could not be resolved because it has an indirect dependency on the framework assembly "System.IdentityModel.Selectors, Version=3.0.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.ServiceModel" or retarget your application to a framework version which contains "System.IdentityModel.Selectors, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

Properties\Resources.resx(123,5): error RG0000: 未能加载文件或程序集“System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或它的某一个依赖项。系统找不到指定的文件。行 123,位置 5。

 

2 做如下修改

(1)Solution Explorer下  找到References ,“Remove”下面各项(图标显示了黄色!号)

Microsoft.CSharp

System.Core

System.Data.DataSetExtensions

System.Runtim.Serialization

Sysem.ServiceModel

System.Xml.Ling

(2)Solution Explorer下  找到Property,双击“Resources.resx”

       Resources.resx下切换到images分类,所有image删掉,重新添加。注意名称必须一致。

(3) 重新编译。错误如下:

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\WaitFrm.cs(6,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\Model\Config.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Task.cs(8,29): error CS0234: The type or namespace name 'ExtractService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\ConfigManager.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(6,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(12,7): error CS0246: The type or namespace name 'Framework' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(15,29): error CS0234: The type or namespace name 'QuerySpaceService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(16,29): error CS0234: The type or namespace name 'QueryStatusService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\XmlHelper.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(4,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(7,29): error CS0234: The type or namespace name 'QuerySpaceService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Job.cs(4,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Job.cs(10,29): error CS0234: The type or namespace name 'RegSpaceService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Common.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\Model\Compress.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\IconReader.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\JobDetails.cs(6,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\ConfigForm.cs(6,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\Model\UserInfo.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\LoginForm.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\LoginForm.cs(8,29): error CS0234: The type or namespace name 'LoginService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\LoginForm.cs(12,29): error CS0234: The type or namespace name 'LicenseService' does not exist in the namespace 'jp.co.solxyz.transfer' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Utils.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\Model\CustomConstDef.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\CustomThreadPoolDAL.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\Model\MFileInfo.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\Program.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\v\Code\convert2FX2\Transfer\Transfer\Model\Upload.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\WaitFrm.Designer.cs(74,17): error CS0246: The type or namespace name 'Framework' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Task.cs(29,17): error CS0246: The type or namespace name 'ExtractServicePortTypeClient' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(29,14): error CS0246: The type or namespace name 'XpProgressBar' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(43,9): error CS0246: The type or namespace name 'QueryStatusServicePortTypeClient' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(210,60): error CS0246: The type or namespace name 'Folder' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Job.cs(751,36): error CS0246: The type or namespace name 'Folder' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\LoginForm.cs(26,9): error CS0246: The type or namespace name 'LoginServicePortTypeClient' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\LoginForm.cs(27,9): error CS0246: The type or namespace name 'LicenseServicePortTypeClient' could not be found (are you missing a using directive or an assembly reference?)

Compile complete -- 36 errors, 0 warnings

 

3  做如下修改:

(1)注掉所有“using System.Linq;”    

(2)service下所有web service删除,重新导入; 

 (3)修改所有webservice调用方式;以下示例

原来的:

LoginServicePortTypeClient remoteLogin;

remoteLogin = new LoginServicePortTypeClient("LoginServiceHttpSoap12Endpoint", remoteaddress);

userinforv = remoteLogin.login(param);

现在的:

Company.LoginService.LoginService loginService = new Company.LoginService.LoginService();

loginService.Url = remoteaddress;

userinforv = loginService.login(param);

(4)重新编译,错误如下:

------ Build started: Project: Transfer, Configuration: Release x86 ------

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(634,67): error CS0019: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(645,68): error CS0019: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(119,24): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(125,40): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(149,17): error CS0246: The type or namespace name 'QuerySpaceServicePortTypeClient' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\v\Code\convert2FX2\Transfer\Transfer\AddJob.cs(149,66): error CS0246: The type or namespace name 'QuerySpaceServicePortTypeClient' could not be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(162,31): error CS0234: The type or namespace name 'ServiceModel' does not exist in the namespace 'System' (are you missing an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(214,38): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\v\Code\convert2FX2\Transfer\Transfer\AddJob.cs(235,48): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(265,52): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(308,44): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(323,40): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(359,46): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(380,47): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\AddJob.cs(394,84): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Job.cs(538,44): error CS1061: 'System.Collections.Generic.Dictionary<string,System.Collections.Generic.List<jp.co.solxyz.transfer.Model.MFileInfo>>.KeyCollection' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Collections.Generic.Dictionary<string,System.Collections.Generic.List<jp.co.solxyz.transfer.Model.MFileInfo>>.KeyCollection' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Job.cs(856,76): error CS1015: A class type expected

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\DAL\Job.cs(1018,49): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\LoginForm.cs(95,32): error CS1061: 'System.Array' does not contain a definition for 'Count' and no extension method 'Count' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?)

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\EXListView.cs(315,13): warning CS0162: Unreachable code detected

Compile complete -- 19 errors, 1 warnings

 

4 做如下修改

(1)  Array.count()错误,统一修改为.Length;

(2)  Collect.ToList() 错误,修改为手工的代码:

            List<String> keys = new List<string>();

            Dictionary<String, List<MFileInfo>>.KeyCollection keyColl = tasks.Keys;

            foreach (string s in keyColl)

            {

                keys.Add(s);

            }

(3)重新编译,错误如下:

------ Build started: Project: Transfer, Configuration: Release x86 ------

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(634,67): error CS0019: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\MainForm.cs(645,68): error CS0019: Operator '+' cannot be applied to operands of type 'System.IntPtr' and 'int'

G:\Transfer\005WorkFolder\whs\Code\convert2FX2\Transfer\Transfer\EXListView.cs(315,13): warning CS0162: Unreachable code detected

Compile complete -- 2 errors, 1 warnings

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

 

5 做如下修改:

通过手工的方法实现IntPtr的偏移

ptr.Ptr = m.LParam;                       

 IntPtr intPtrFilePath = new IntPtr(m.LParam.ToInt32() + 4);

  //String filename = Marshal.PtrToStringAuto(ptr.Ptr + 4); // PtrToStringUni

  String filename = Marshal.PtrToStringAuto(intPtrFilePath); // PtrToStringUni

 

至此编译通过,但是实验结果如下:

在安装了.net framework3.5sp1的机器上工作正常。(实际上此FX包含3.5,3.0,2.0)

在windows2000下,在安装了FX2.0后,程序不能启动,双击没什么反应。由于2000下不能安装FX3.5,FX3.0,只好实验在vs2005下编译此项目。

 

 

 

 

 

原创粉丝点击