Reputation: 10108
I know how to set the C# language version to use the latest syntax (Project > Properties > Build > Advanced > Language settings...) This always defaults to 'C# latest Major version (default)'
Is there any way to get Visual studio to default a new project's language version to a non-default value; preferably to the 'C# latest minor version (latest)'?
Effectively, I'd like latest
passed to MSBUILD as the langversion
parameter for any new project I create in VS2017 without having to remember to change this setting.
Edit - to address possible duplicate post about a link I already included in my original question... I don't really want to do this by altering 'Microsoft.Common.props' as suggested in the afore mentioned link because I'll have to change all my build machines to include this by default (the build machines should just run MSBuild; they should not include directives that may not be applicable to future builds) - ideally the value should be present in the csproj file.
Apologies if this is a duplicate - I have searched this site extensively, and also googled for an answer - but I haven't found an answer yet.
EDIT - NEW INFO - OCT 2019
VS2019 Has resolved this issue for me - see link. Depending on which version of the framework you use, you get a different language version target by default. This isn't quite what I was after, but it solves my problem. After lodging a problem ticket with Microsoft, it turns out that they are not willing to change VS2017 to do the same, so it's upgrade time for me!
Upvotes: 3
Views: 5021
Reputation: 100543
While it does not change the default for all new solutions+projects, for larger projects you are working on, you can create a Directory.Build.props
file in your solution directory (or any directory you want it to apply to, could even be your C:\Users
directory).
In this file, you can set all sorts of defaults for all projects:
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>
This helps a lot for larger projects so that all new projects you add to the solution will have the same configuration.
Upvotes: 4
Reputation: 76670
Set the default C# Build Language Version in Visual Studio 2017
Just like Matthew commented, you could create a custom project template with that setting.
When you want to set langversion
parameter for any new project, you can create the new project with your custom project template, otherwise, use the default template.
Note: If you just set this setting for one solution, not multiple solutions, Martin's advice is also a good choice.
Hope this helps.
Upvotes: 2