Compiler Options - C# reference (original) (raw)

This section describes the options interpreted by the C# compiler. Options are grouped into separate articles based on what they control, for example, language features, code generation, and output. Use the table of contents to navigate amongst them.

How to set options

There are two different ways to set compiler options in .NET projects:

<PropertyGroup>  
  <LangVersion>preview</LangVersion>  
</PropertyGroup>  

For more information on setting options in project files, see the article MSBuild properties for .NET SDK Projects.

.NET Framework projects

Important

This section applies to .NET Framework projects only.

In addition to the mechanisms described above, you can set compiler options using two additional methods for .NET Framework projects:

The word for some compiler options changed from csc.exe and .NET Framework projects to the new MSBuild system. The new syntax is used throughout this section. Both versions are listed at the top of each page. For csc.exe, any arguments are listed following the option and a colon. For example, the -doc option would be:

-doc:DocFile.xml

You can invoke the C# compiler by typing the name of its executable file (csc.exe) at a command prompt.

For .NET Framework projects, you can also run csc.exe from the command line. Every compiler option is available in two forms: -option and /option. In .NET Framework web projects, you specify options for compiling code-behind in the web.config file. For more information, see Element.

If you use the Developer Command Prompt for Visual Studio window, all the necessary environment variables are set for you. For information on how to access this tool, see Developer Command Prompt for Visual Studio.

The csc.exe executable file is usually located in the Microsoft.NET\Framework\ folder under the Windows directory. Its location might vary depending on the exact configuration of a particular computer. If more than one version of .NET Framework is installed on your computer, you'll find multiple versions of this file. For more information about such installations, see How to: determine which versions of the .NET Framework are installed.