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…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If all else fails, try it. I’ve just tested the following in VS2010b2, compiled targeting 2.0:
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
cscat 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:
And sure enough:
works fine (exe works on my non-4.0 machine). Credit: Kevin Pilch-Bisson