Roslyn: can you Configure roslyn's default language version?

Created on 8 Jun 2018  路  5Comments  路  Source: dotnet/roslyn

i've poked around the docs but not found anything about how to do this but i may have missed something

is there a way to get roslyn to default to latest minor version instead of latest major version

with the languages now running on minor versions for changes (ie c#7.3) it can be a real pain having to go in to every project to set the language to latest instead of default

as this selection is a compiler setting not a IDE setting is there a way to set your own preference at the compiler with out having to rebuild it?

if the ability to customise your own preference for default isn't available, could you provide a way to do this system wide?

Also would it make sense to switch the default to latest minor?

when the languages were only using minor versions for testing features and the Major versions being the stable releases the default to latest major made sense

but now the minor versions are also stable releases and i know very few developers that wouldn't prefer the latest stable to be the default so

Area-IDE Question Resolution-Answered

Most helpful comment

with the languages now running on minor versions for changes (ie c#7.3) it can be a real pain having to go in to every project to set the language to latest instead of default

You can set the value in a Directory.Build.props file in the solution root. The project system will automatically include the file with that name and evaluate it before the rest of the contents of the project. Here is an example of where it's set in the PerfView solution to apply to all projects:

https://github.com/Microsoft/perfview/blob/f2a11fca935fb074cb2c0cc98ccc0e8e77872881/src/Directory.Build.props#L8-L11

or at least provide a way for users to set there own preference system wide;

This is a really bad idea for most large development teams. A setting like this would mean each individual developer's build can vary according to the specific update of Visual Studio they have installed. In a team setting, new language features should only start to work once the team has decided as a whole to update to the minimum IDE version supporting that language version, and the setting should be explicitly coded as part of the solution/project.

In some limited scenarios, users may wish to ignore this versioning recommendation. The workaround described above can be used in these cases to apply <LangVersion>latest</LangVersion> automatically to all projects in a solution.

All 5 comments

with the languages now running on minor versions for changes (ie c#7.3) it can be a real pain having to go in to every project to set the language to latest instead of default

You can set the value in a Directory.Build.props file in the solution root. The project system will automatically include the file with that name and evaluate it before the rest of the contents of the project. Here is an example of where it's set in the PerfView solution to apply to all projects:

https://github.com/Microsoft/perfview/blob/f2a11fca935fb074cb2c0cc98ccc0e8e77872881/src/Directory.Build.props#L8-L11

or at least provide a way for users to set there own preference system wide;

This is a really bad idea for most large development teams. A setting like this would mean each individual developer's build can vary according to the specific update of Visual Studio they have installed. In a team setting, new language features should only start to work once the team has decided as a whole to update to the minimum IDE version supporting that language version, and the setting should be explicitly coded as part of the solution/project.

In some limited scenarios, users may wish to ignore this versioning recommendation. The workaround described above can be used in these cases to apply <LangVersion>latest</LangVersion> automatically to all projects in a solution.

if that argument is valid then the options of default and latest should be removed entirely and should be replaced with a selector like the frameworks have as defaulting with out the option to select in advance has already had the effect you are warning against

@MikeLeicester The values can't be changed for backwards compatibility reasons, but I was able to make some UI updates to encourage the use of explicit versions in #23392.

@MikeLeicester Please note that while I definitely have a recommendation that I stick with, you can count on consistent behavior regardless of the language version strategy you use for your project:

  • Specific versions match that version
  • default matches the latest major version (as known to the currently installed compiler)
  • latest matches the latest minor version (as known to the currently installed compiler)

These values will remain with the same behavior in future releases.

Regardless of the LangVersion value you choose, Directory.Build.props will be the easiest place to put it. You can also put a .props file in the following location and it will get picked up by all builds you run on your machine:

$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Imports\Microsoft.Common.props\ImportBefore\

@MikeLeicester Please feel free to let us know if you have other questions or concerns. 馃槃

Was this page helpful?
0 / 5 - 0 ratings