简体   繁体   English

从.NET 2.0迁移到.NET 4.0

[英]Migrating from .NET 2.0 to .NET 4.0

What are the changes I need to make to a application built with .NET 2.0 /C# in order to use the C# 4.0 features . 为了使用C#4.0功能,我需要对使用.NET 2.0 / C#构建的应用程序进行哪些更改。 Recently I ran into a problem, when trying to add optional paramters in a product which was developed on .NET 2.0 / C# 2.0 . 最近,在尝试在.NET 2.0 / C#2.0开发的产品中添加可选参数时,我遇到了一个问题。

Most 2.0 programs works without any changes on 4.0. 大多数2.0程序可以在4.0上进行任何更改。 It was only on 1.1 to 2.0 that there was a lot of incompatible changes. 只是在1.1到2.0上,存在许多不兼容的更改。

One problem, that I ran into recently when upgrading a 3.5 project to 4.0 (Visual Studio 2008 to Visual Studio 2010), was that after upgrading to 4.0 I did not have a reference to System.Core and was unable to add it via Visual Studio instead displaying a message: 我最近在将3.5项目升级到4.0(Visual Studio 2008到Visual Studio 2010)时遇到的一个问题是,在升级到4.0之后,我没有对System.Core的引用,并且无法通过Visual Studio添加它而是显示一条消息:

A reference to 'System.Core' could not be added. 无法添加对“System.Core”的引用。 This component is already automatically referenced by the build system. 构建系统已自动引用此组件。

You will need to have a reference to System.Core if you want to use the var keyword and LINQ extension methods. 如果要使用var关键字和LINQ扩展方法,则需要引用System.Core

It can be manually added (or readded if removed). 可以手动添加(如果删除则读取)。 See the blog post System.Core in VS2010 Projects for details. 有关详细信息,请参阅VS2010项目中的博客文章System.Core

Maybe you migrated your Visual Studio solution to 2010, but you forgot to change the target framework to 4.0 in projects' properties. 也许您将Visual Studio解决方案迁移到了2010,但是您忘记在项目属性中将目标框架更改为4.0。

Just go to properties in your solution projects (obviously, the migrated to Visual Studio 2010 solution) and change the target framework to 4.0. 只需转到解决方案项目中的属性(显然,迁移到Visual Studio 2010解决方案)并将目标框架更改为4.0。

That's all your C# code base will be using .NET Framework 4.0 and C# 4.0. 这就是您的所有C#代码库都将使用.NET Framework 4.0和C#4.0。 I'm pretty sure you won't need to change your code, but, maybe, you'll find that some classes, methods, properties are now obsolete, but it'll compile anyway. 我很确定你不需要改变你的代码,但是,也许,你会发现一些类,方法,属性现在已经过时了,但无论如何它都会编译。

Comment out if you don't know how to do that. 如果您不知道该怎么做,请注释掉。

In theory, C# 4 should be backwards compatible with C# 2. 从理论上讲,C#4应该与C#2向后兼容。
In practice, I've done it several times with no problems, and I think the only obvious problem is if you have named some classes that are defined by the .net 4.0 framework. 在实践中,我已经完成了几次,没有任何问题,并且我认为唯一明显的问题是,如果您命名了一些由.net 4.0框架定义的类。

You cannot use .NET 4.0 specific features in an application targeting .NET 2.0. 您不能在面向.NET 2.0的应用程序中使用.NET 4.0特定功能。 You will need to migrate to .NET 4.0. 您将需要迁移到.NET 4.0。

You can't easily convert form a higher version to a lower version. 不能轻易地将较高版本转换为较低版本。

You can easily convert form a lower version to a higher version. 可以轻松地将较低版本转换为较高版本。

如果我没记错的话,.NET 2.0中的C#不支持可选参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM