Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make each csproj in a solution target a different C# version

Tags:

c#

msbuild

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

like image 483
Shaun Luttin Avatar asked Mar 04 '15 16:03

Shaun Luttin


People also ask

How do you build specific targets in solutions using MSBuild EXE?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

How do I change the solution platform in VS?

On the Build menu, click Configuration Manager. In the Active solution platform box, select the platform you want your solution to target, or select <New> to create a new platform.


1 Answers

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

like image 123
Marc Gravell Avatar answered Sep 30 '22 05:09

Marc Gravell