How do you specify a target framework version for the csc.exe c# compiler via command-line?

I need to force csc.exe to compile for .NET Framework 2.0. I can target .NET 2.0 from VS, but VS is not an option in this case. I must work from the command line.

Can anyone help?

Bill Drago

If you scan your root windows directory, you will notice multiple csc.exe files each in a directory separated by the particular platform.

I would (...have not tested this yet...) use the specific csc.exe found in the \Microsoft.NET\Framework\v2.0.nnnnn\ directory to compile just for Dot Net 2.

[minutes later]
I just tested this and it works by specifying the directory for the target framework.


using System;
using System.Linq;

namespace Test
   public class CTest
      public static void Main(String[] args)
         Enumerable.Range(1, 3).ToList().ForEach(n => Console.WriteLine(n));

C:\science\csharp>c:\winnt\Microsoft.NET\Framework\v2.0.50727\csc.exe One.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.3053
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

One.cs(3,14): error CS0234: The type or namespace name 'Linq' does not exist in
the namespace 'System' (are you missing an assembly reference?)

C:\science\csharp>c:\winnt\Microsoft.NET\Framework\v3.5\csc One.cs
Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.


Edited 5 Years Ago by thines01: Confirmation

Perfect solution to my problem!

That's it! Thank you! It's been driving me mad.

What a relief.


This question has already been answered. Start a new discussion instead.