what .net version VS2005 use for C# project - c#

I am porting a project built on VS2008 to VS2005 since the minor .NET version for us have to 2.0 instead of 3.5 and rest of our code is building on VS2005. So I modified the visual studio version from 2008 to 2005 at the .sln file
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
So I am able to load the .sln into the VS2005. I have some building problem, mainly the "var" and after I modified those lines with real data type, the code compiles and runs.
However at the project assembly reference. I found out that my code is still reference Linq which is from .NET 3.5:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll
When I open up the dialog to add new reference, I could see that the .NET version 2.0, 3.5 and even 4.0 (although the CLR runtime version is 2.0.50727 in most of cases. sometimes 1.x and sometimes 4.0, Linq's runtime version is 2.0.50727).
I thought that VS2005 only supports .NET 2.0 which seems not that case here. So I guess how can I make sure that my application would only require .NET 2.0 framework. Is it enough to make sure that I only reference .NET 2.0 and below reference?

As long as the target framework is .NET 2.0 and you don't reference any libraries that do target higher .NET framework versions, your app should run just fine on .NET 2.0.
That said, I believe Visual Studio 2008 supports multi-targeting, so you should be able to use VS2008 but still target .NET 2.0 as your output type. Additionally, VS2010 and VS2012RC also support .NET 2.0 only projects.
To answer the exact question in the title (for the benifit of those who find this page by its title) the .NET version used by default in Visual Studio 2005 is .NET v2.0.

You can still use VS2008. VS2008 fully supports 2.0-only projects (just change the project settings). When in 2.0 mode VS will disable any 3.0 and 3.5 assemblies as well as any C# language features that depend on 3.0 or 3.5 library classes (such as extension methods, but there is a workaround to get those working with 2.0).
I'll say that VS2010 also supports 2.0-only projects too.

Related

Using SSH.NET on C# Console application in Visual Studio 2008 and .NET Framework 3.5

I have a Visual Studio 2008 project in C# with .NET Framework 3.5 and I would like to use SSH.NET library but I see no binaries there for last stable release 2016.0.0.
Also in home page says it has been moved to here. Once I go to this page, I see three branches, develop, master and sftpfilestream, so which one I have to take which is compatible with .NET Framework 3.5 (My project uses .NET Framework 3.5 on Visual Studio 2008)?
Also If I downloaded any of them, once unzipped I do not see any DLL, only projects. Well, in fact, I prefer to reference a project within mine in order to use it, but by curiosity, where are the binaries (DLLs)? and which project is the correct I have to add to mine for .NET Framework 3.5?

clr DLL built as .NET 3.5 "requires later version" when referenced from a .NET 3.5 project.

I built the dll using Visual Studio 2008 for .NET 3.5 targeted framework.
Loading it into a .NET project built in 3.5 gives the error
"OpenGLControl.dll", or one of its dependencies, requires a later version of the .NET Framework.... etc.
The dll shows a 'runtime version' of v2.0.50727.
Anyone experienced something similar? Any solutions?
According to this site: that should be acceptable for a .NET 3.5 build.
Thanks!
In the end the issue was an unversioned dependency, although not listed as a higher framework version it seems VS2008 'assumed' it to be higher. So not only must the dependencies by the same version or less, they must all have an explicit framework version.

Are assemblies compiled with MsBuild 4.0 compatible with computers which have only .NET 3.5?

In a project which target framework is 3.5 the following line compiles with MsBuild 4.0:
aEnumerable.Select(aMethod);
But MsBuild 3.5 requires me to write:
aEnumerable.Select(item => aMethod(item));
Will both binaries will run a machine without .NET Framework 4.0, but with .NET 3.5?
PS: While i showed an example using "method overload inference" the same happens with other "4.0" features (eg. "named parameters").
another title for this question could be: What C# 4.0/Visual Studio 2010 features are .NET 3.5 compatible?
You are confusing Msbuild and the .NET framework.
Msbuild is just a tool to build .NET projects. Version 4.0 is required to build .NET 4 projects, but it can also do .NET 1.1, 2.0, 3.0, 3.5, 3.5 SP1. Its just like using Word 2010 to open a Word 2003 file. 2010 will open both, but 2003 will crash if you give it a 2010 file
Your code examples are showing differenecs added to the framework in version 4.0. You cannot execute .NET 4 code on a machine that doesn't haven't the .NET 4.0 framework installed. Doesn't matter what builds it, the runtime will not be able to understand the CLR and it won't run
As for msBuild itself:
MsBuild 4.0 is a new version, largely updated to support .NET 4, but also with its own features. Consult the release notes for msbuild4 if you need those details.
That said, MsBuild 4 is fully capable of producing .NET 3.5 output so long as the targetFramework is properly configured. (We moved all our builds to MsBuild 4.0 long before we upgraded all projects to the .NET 4 framework)
If you target the installation to .NET 3.5 SP 1 and it works then it will work on a machine with just .NET 3.5 Service Pack 1. If your not targeting 3.5 SP1 you should.
Version 3.5 of MSBuild, which is
bundled together with .NET 3.5 (and
Visual Studio 2008), allows .NET
projects to be built for either 2.0,
3.0 or 3.5 .NET version support (also known as"multi-targeting").
Source
I would extrapulate that MSBuild 4 would be updated to also support .NET Framework 4.0. You should of course test your installations yourself a virtual machine and make sure everything works.
I just wanted to clarify that you should be using the MsBuild 3.5 method if you want to remove any compability issues that might arise otherwise. I suspect that MSBuild 4.0 would keep support for the older method but was just updated to support changes that happen in the 4.0 .NET Framework.
A command similar to the following
should work
msbuild YourSolution.sln /tv:3.5
/p:TargetFrameworkVersion=v3.5 or
msbuild YourSolution.sln
/p:TargetFrameworkVersion=v3.5 /tv (or
/toolsversion) Indicates which version
of the MSBuild tools you want to use,
and the property
TargetFrameworkVersion indicates the
target framework. In your case just
specifying that property should be
fine, but if you want to use the 3.5
MSBuild toolset you can sepcify it
with /tv as I did in the first
command.
Source

Rookie build and deployment a dynamic library question

I had a request to write a dll library using C#, it should be build under .NET 3.5.
I've build the library (it's a simple TCP client) using Visual Studio 2005 with .NET 2.0.50727.
I'm assuming that I can not deliver this library since it's built against wrong .net
I have more .NET versions installed on my development machine but it looks like I can't switch the .net in properties like JDK versions in eclipse for a particular project.
Is the only proper way of doing this is installing Visual Studio 2008 Express with 3.5 .NET?
Or some C# sdk with appropriate compiler (the thing is that I don't know the syntax for the c# compiler and NANT would be pain in the ass at this stage)?
cheers
P.
As jgauffin already mentioned your .Net 2.0 assembly will work fine in .Net 3.5.
And switching to another .Net Framework is just downwards possible.
So with VS2010 you can built against .Net 4, 3.5, 2.0 and 1.1
With VS2008 you can built against .Net 3.5, 2.0 and 1.1
With VS2005 you can built only against .Net 2.0
With VS2003 you can built only against .Net 1.1
So if you really need it just go and download it from here.
3.5 is just 2.0 with additional libraries. Your DLL will work fine from a .Net 3.5 application.
I might be wrong, but I think that 3.5 was introduced with Visual Studio 2008 and cannot be built against with 2005. That's why you can't switch version.

Can I use all C# 4.0 features in a project that targets .Net 3.5?

Development Environment :
- VS2010
- .Net Framework 4.0, 3.5, 2.0
Staging and Production Environments:
- .Net Framework 3.5, 2.0
The project I'm working on is targeting .Net Framework 3.5. And today I used optional parameters feature, which is new to C#4, in this project and it worked fine. I think VS2010 is using C#4 compiler and is compiling the method with optional parameters to corresponding overloaded methods in IL.
I want to know if I can use all new C#4 features as well.
You cannot use is the dynamic feature. This relies on the C# runtime and DLR DLL's which are only available on the 4.0 version of the .Net framework. Versions of the DLR are available for 3.5 but I do not believe they are compatible with the one required by the C# compiler.
Additionally you cannot use NoPIA / Embedded Interop Types in a down targetted scenario. This feature requires CLR support that was added in 4.0.
What's great about down targeting in Visual Studio 2010 though is you don't have to be aware of every limitation. If your projects are set to down target 3.5 and you use an incompatible feature, Visual Studio will produce an error.
I bumped into this a couple of weeks ago actually. I used optional parameters even though the project targeted .net 3.5. You need to be very careful of this because if you install the application on a computer that only has .net 3.5 runtime installed then your program may not run. In my case, I used the optional params and the nightly build server only had 3.5 installed so the build failed.

Categories