Martín
Martín

Reputation: 33

Visual Studio version and .NET target version

I use VS 2005 and .NET 2.0 SP 2.

If I install VS 2008 and .NET 4 on the same machine, without uninstalling VS 2005, and I keep using VS 2005 to build some applications, will these applications keep targeting .NET 2.0, or they will require .net 4.0?

I have read that with VS 2008 it is possible to choose which .NET version to target, but what about VS 2005?

Thanks in advance.

Upvotes: 3

Views: 9914

Answers (2)

Security Hound
Security Hound

Reputation: 2551

Bad Display Name has not actually helped the author.

He fails to mention the following from the very article he quoted in his comment to me.

Yes, that's to be expected I'm afraid. Installing .NET 3.5 doesn't upgrade the compilers you get with Visual Studio 2005. You have to get VS 2008 if you want to use the new C# or VB.NET syntax. I mentioned this absence of compiler support in the article.

There is, of course, a distinction between sytax that is understood by a compiler, and the underlying libraries and types that the syntax expolits. You still have full access to Linq technologies, but you have to write code using 'standard' syntax.

Here is the above code (plus some additional code to print out the results) written 'long-hand'. This compiles in VS 2005. You need to give your project a reference to System.Core v3.5 and import the System.Linq namespace.

int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

//var numsPlusOne = from n in numbers select n + 1; IEnumerable numsPlusOne = Enumerable.Select(numbers, delegate(int n) { return n + 1; });

foreach (int nNew in numsPlusOne) { Console.WriteLine(nNew); }

OK, my blog is clearly leading to misunderstandings, and I need to carefully qualify what is going on here. People need to make a very clear distinction in their minds between different things:

a) The .NET Framework The framework is chiefly composed of a library of pre-written object orientated code -i.e., a class library, or perhaps more accurately, a set of libraries.

b) The C# and VB.NET compilers These are written as .Net assemblies. The new compilers are bundled with the framework.

c) The C# and VB.NET editing and compilation support provided in Visual Studio. Starting with Visual Studio 2008, Microsoft has enhanced these tools so that you can easily target different versions of the framework. This includes targeting different versions of the C# and VB.NET compilers.

Note the following points:

• All .NET 3.5 code complies with the standardised definitions for version 2.0 of the Common Language Runtime. This includes all the code in the class libraries, including Linq, and even the code in the compiler assemblies. Hence, Visual Studio 2005 can access any public members of any public classes anywhere in the library, and can even reach protected and private members via reflection. This is why you can happily exploit WCF 3.5 within Visual Studio 2005.

• Visual Studio 2005 predates .NET 3.5 and therefore its code editing and compilation features do not target or support the versions of the compilers provided with .NET 3.5. Hence, there is no support for new syntax supported by the latest compilers, which is why Chris' code won't compile (it uses the new object initializer syntax).

Syntax supported in a compiler is one thing. The underlying classes and other types exploited by specialised syntax such as Linq are something different. You don't have the ability to use the new Linq syntax in the old version of Visual Studio. You do, however, have the ability to access the underlying class libraries directly using 'traditional' syntax.

Having said all this, I could be irresponsible and point out that Microsoft did release some Linq CTP tooling for Visual Studio 2005. This is still available at:

http://www.microsoft.com/downloads/details.aspx?familyid=1e902c21-340c-4d13-9f04-70eb5e3dceea&displaylang=en.

It may be possible to use this in conjunction with careful changes to Microsoft.CSharp.targets referenced in the MSBuild script contained in your project files in order to convince Visual Studio 2005 to support the latest syntax and compilers. I wouldn't recommend this, as this depends on CTP code, which may not offer complete support for the syntax supported in the release version of Visual Studio 2008, and a degree of black-belt manipulation of the mechanics of Visual Studio. I take no responsibility for any problems people might encounter if they try to get this to work!

In other words the author of the article suggested what amounts to be a hack, the ide will not check your syntax, and you won't be able to implement any C# 3.5 syntax changes within VS05.

Upvotes: 2

Ruslan
Ruslan

Reputation: 10147

You can have multiple major versions of .NET Framework installed and you can target any of them in Visual Studio 2008 or 2010, just go to Project's Property Pages > Build > Target Framework or Properties > Application > Target Framework (depending on project type) to pick one.

EDIT: The above function is not available in VS2005 and it will target .NET 2.0 by default. To use it with other versions of framework, you'd need to fiddle with references a bit (i.e. replacing .net 2.0 dlls with other version's dlls).

Upvotes: 3

Related Questions