5

I have a solution that contains five C# console application projects. I would like each project to target a different version of C#.

MyLearningSolution.sln
    CSharp01.csproj
    CSharp02.csproj
    CSharp03.csproj
    CSharp04.csproj
    CSharp05.csproj

Is there a way to do this either via Visual Studio or via editing each csproj file?

I have tried the following searches:

  • csproj target specific C# version, this talks about targeting a specific framework version

  • csproj choose c# version, doesn't answer the question

0

2 Answers 2

11

This can be done by looking at the <LangVersion> element of the csproj file. Possible values:

<LangVersion>default</LangVersion>
<LangVersion>ISO-1</LangVersion>
<LangVersion>ISO-2</LangVersion>
<LangVersion>3</LangVersion>
<LangVersion>4</LangVersion>
<LangVersion>5</LangVersion>

To do it via the UI, go to Project Properties => Build => Advanced... => Language Version

Sign up to request clarification or add additional context in comments.

1 Comment

I think its worth pointing out LangVersion and actually using an older compiler version are subtly different. Eric Lippert explains it here.
7

Right click on Project, go to Properites, There under Build click the Advanced.. button, there you can specify Language version.

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.