If all else fails, try. I just tested the following in VS2010b2, compiled targeting 2.0:
using System; class Program { static void Main() { Write(); Write(msg: "world"); Console.ReadLine(); } static void Write(string msg = "Hello") { Console.WriteLine(msg); } }
It uses two new features of C # 4.0, which use metadata, which is also present in .NET 2.x / 3.x / CLR 2; it works fine on my regular machine (CLR 2) (my VS2010b2 is a virtual machine). Therefore, I conclude "yes, for some functions." Obviously, if you use a structure-dependent function ( dynamic , etc.), it will not be so good.
Edit: repeat your comment; I tried csc on the command line, and by default this points to CLR 4; I will try to see if I can get it for the target CLR 2 (e.g. VS). Unfortunately, it no longer includes the command line (faked, btw) in the assembly output window ...
Update: Some βup to dateβ people have returned using:
Pass / nostdlib and a link to the 2.0 mscorlib.dll file.
And of course:
C:\Windows\Microsoft.NET\Framework\v4.0.21006>csc /nostdlib /reference:%SystemRo ot%\microsoft.net\framework\v2.0.50727\mscorlib.dll /out:c:\my.exe /target:exe " C:\Users\Marc\Documents\Visual Studio 2010\Projects\ConsoleApplication6\ConsoleA pplication6\program.cs" Microsoft (R) Visual C# 2010 Compiler version 4.0.21006.1 Copyright (C) Microsoft Corporation. All rights reserved.
works fine (exe runs on my machine other than 4.0). Credit: Kevin Pilch-Bisson
Marc gravell
source share