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

1.2k views Asked by At

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?

2

There are 2 answers

2
Taylor Bird On BEST ANSWER

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)

3
Security Hound On

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