I have a solution with 20 projects, I want to change the C# version for all of them to C# 7.3
Is there a way that I could change all project's version at one go? I know I can change the Language Version from Project's Properties, but I don't want to repeat this 20 times.
To set a version for all your project at once, you can create a file named Directory.Build.props
(case-sensitive on Linux) at the root of your repository. This file contains the list of common properties of your projects:
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<!--<LangVersion>preview</LangVersion>-->
<!--<LangVersion>7.3</LangVersion>-->
</PropertyGroup>
</Project>
https://www.meziantou.net/4-ways-to-enable-the-latest-csharp-features.htm#method-4-using-a-pro
The accepted answer is great, I am just adding some details.
I created Directory.Build.props
file at the root of the of the repository and added it to the solution as a Solution Item. This is the content of the file:
<Project>
<PropertyGroup>
<LangVersion>7.3</LangVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
</Project>
If you modify these setting, you need to restart Visual Studio for the changes to take effect.
You would require MSBuild version 15 or higher in order to use Directory.Build.props
. To check MSBuild version, open your project file in a text editor and look for the following:
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Here, 15.0
indicates your MSBuild version, see this document if you require to upgrade your MSBuild version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With