简体   繁体   中英

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 . 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 .

Most 2.0 programs works without any changes on 4.0. It was only on 1.1 to 2.0 that there was a lot of incompatible changes.

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:

A reference to 'System.Core' could not be added. 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.

It can be manually added (or readded if removed). See the blog post System.Core in VS2010 Projects for details.

Maybe you migrated your Visual Studio solution to 2010, but you forgot to change the target framework to 4.0 in projects' properties.

Just go to properties in your solution projects (obviously, the migrated to Visual Studio 2010 solution) and change the target framework to 4.0.

That's all your C# code base will be using .NET Framework 4.0 and 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.
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.

You cannot use .NET 4.0 specific features in an application targeting .NET 2.0. You will need to migrate to .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#不支持可选参数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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