I don't believe you can do so. You can set a language version in the project properties, but that's not the same as using the C# 3 compiler from .NET 3.5. I believe there are subtle differences around type inference and overload resolution, for example, where the C# 4 rules will be followed instead of the C# 3 rules, even when building as C# 3. Here's an example of that:
using System;
class Test
{
static void Main()
{
CallFunc(Demo);
}
static int Demo() { return 5; }
static T CallFunc<T>(Func<T> func)
{
return func();
}
}
This builds using the C# 4 compiler, even when you specify /langversion:3 - but it doesn't build with the C# 3 compiler.
You may find that you can tweak the project file to use the previous version of the compiler - but I don't know how Visual Studio would deal with that. I suspect it would get hideously confused.
EDIT: Okay, now you've given the motivation, I think you may want to do what we do for Noda Time. We have a VS2010 solution and a VS2008 solution file. They both load the same projects, which have a ToolsVersion
attribute of 4.0. I haven't tried, but I believe that should build absolutely fine on a machine with only .NET 3.5.
You may well want to set the language version to 3 as well in your project files, to avoid accidentally using new features. It won't make your compatibility bullet-proof, but if you've got all your unit and integration tests building and running on a .NET 3.5-only continuous build server, you're unlikely to get bitten by the changes.