How can I compile .NET 3.5 C# code on a system without Visual Studio?

Posted by JimEvans on Stack Overflow See other posts from Stack Overflow or by JimEvans
Published on 2011-02-17T14:32:44Z Indexed on 2011/02/17 15:25 UTC
Read the original article Hit count: 210

Filed under:
|

I have some C# code that uses some constructs specific to .NET 3.5. When you install the .NET Framework distribution, you get the C# compiler installed with it (csc.exe). Even if I specify the csc.exe in C:\Windows\Microsoft.NET\Framework\v3.5, I cannot compile the code on a computer with only the .NET Framework installed, but not Visual Studio. I am able to compile code that uses v2.0 constructs without difficulty. How can I accomplish this?

Here is a sample that demonstrates my problem:

using System;
class Program
{
    public static void Main()
    {
        // The MacOSX value to the PlatformID enum was added after
        // .NET v2.0
        if (Environment.OSVersion.Platform == PlatformID.MacOSX)
        {
            Console.WriteLine("Found mac");
        }
        Console.WriteLine("Simple program");
    }
}

When compiling this code using csc.exe, I receive the following error:

test.cs(9, 58): error CS0117: 'System.PlatformID' does not contain a definition for 'MacOSX'

When executing csc.exe /? I receive the banner:

Microsoft (R) Visual C# 2008 Compiler version 3.5.21022.8
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

© Stack Overflow or respective owner

Related posts about c#

Related posts about .net-3.5