Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can IL produced by C# 4.0 compiler run on CLR 2.0?

Tags:

c#

.net

Can IL produced by C# 4.0 compiler run on CLR 2.0?

To clarify, I'm not asking about VS 2010 multi-targeting (where VS chooses the right compiler version), I want to know if csc.exe 4.0 supports multi-targeting...

like image 253
Max Toro Avatar asked Oct 23 '09 01:10

Max Toro


People also ask

What is interleukin produced by?

One of a group of related proteins made by leukocytes (white blood cells) and other cells in the body. Interleukins regulate immune responses.

Is IL-10 produced by Th2?

IL-10 was originally described as a cytokine produced specifically by CD4+ Th2 cells, but later studies showed that it was secreted by both Th1 and Th2 cells.

How is Il 1a produced?

IL-1α is produced mainly by activated macrophages, as well as neutrophils, epithelial cells, and endothelial cells. It possesses metabolic, physiological, haematopoietic activities, and plays one of the central roles in the regulation of the immune responses. It binds to the interleukin-1 receptor.

Is IL-1 produced by macrophages?

IL-1 is produced predominantly by macrophages and macrophage-like cells but also by endothelial and epithelial cells. IL-1 has two forms, IL-α and IL-β, encoded by two separate genes, which bind to the same IL-1 receptors.


1 Answers

If all else fails, try it. I've 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);
    }
}

This uses two new C# 4.0 language features, which use the meta-data that is also present in .NET 2.x/3.x/CLR 2; it executes fine on my regular (CLR 2) machine (my VS2010b2 is a VM). So I conclude "yes, for some features". Obviously if you use a framework-dependent feature (dynamic, etc) it isn't going to end so well.

Edit: re your comment; I've tried csc at the command-line, and by default this does target CLR 4; I'll try to see if I can get it to target CLR 2 (like VS obviously can). Unfortunately, it no longer includes the (faked, btw) command line in the build output window...

Update: some "in the know" people came back with:

Pass /nostdlib and a reference to the 2.0 mscorlib.dll.

And sure enough:

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 works on my non-4.0 machine). Credit: Kevin Pilch-Bisson

like image 189
Marc Gravell Avatar answered Sep 19 '22 10:09

Marc Gravell