您可以/r
指定舊的.NET程序集:
/reference:<alias>=<file> Reference metadata from the specified assembly
file using the given alias (Short form: /r)
/reference:<file list> Reference metadata from the specified assembly
files (Short form: /r)
您還需要壓制自動加上現代的mscorlib與/nostdlib
:
/nostdlib[+|-] Do not reference standard library (mscorlib.dll)
總之,這些做起來很您可以使用C#6編譯器構建.NET 2.0應用程序。
csc.exe /r:"C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /nostdlib Program.cs
您甚至可以在您的應用程序中使用C#6功能! (只要它們是不包含.NET運行庫的僅編譯器功能)
public static string MyProp { get; } = "Hello!";
static void Main(string[] args)
{
Console.WriteLine(MyProp);
// prints "Hello!"
var assembly = Assembly.GetAssembly(typeof(Program));
Console.WriteLine(assembly.ImageRuntimeVersion);
// prints "v2.0.50727"
}
我只是對不再支持2.0的強制性警告發表評論。 –