LazyCodet

a

16:19:22 7/5/2025 - 1 views -
Programming

How to Change C# Language Version for All Projects

​If you want to use new C# features like raw string literals (C# 11) or pattern matching improvements, you need to set the correct C# language version in your project.

Instead of setting it manually in every .csproj file, you can apply it globally using a file called Directory.Build.props.


βœ… Steps to Set C# Version Globally

Go to the root folder of your solution

This is the folder where your .sln file is located.

Create a file named Directory.Build.props

Make sure to name it exactly like that (case-sensitive on Linux/macOS).

Add this content to the file:

<Project>
  <PropertyGroup>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>
</Project>

You can replace latest with a specific version like 11.0, 12.0, or preview.


βœ… Example Result

Now all projects under the solution will automatically use that C# version, without needing to modify each .csproj.


That’s it! This is a clean and easy way to control your C# language version across the whole solution.