How can I compile .NET 3.5 C# code on a system without Visual Studio?
- by JimEvans
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.