Reputation: 8703
I have a csproj with <LangVersion>default</LangVersion>
, which is currently defaulting to c# 7.0.
If I change it manually to 7.3, it correctly compiles our code which uses certain features from 7.1 and higher.
Of course I could change this on every csproj, but as we have a lot I'm looking towards other solutions.
I've added a Directory.Build.props at the root of my repository, and am importing it into a csproj. But the setting for <LangVersion>
from the csproj is taking precedence over the setting for <LangVersion>
from my props file... no matter where I import it in the csproj.
I'd rather not ask everyone to remove the <LangVersion>
property from their csproj and all future csproj if this can be inherited from some master props... but that doesn't seem to be the case. What am I missing here?
Upvotes: 3
Views: 1484
Reputation: 100751
The Directory.Build.props
file is imported automatically (no <Import>
needed) at the beginning (!) of the project file.
So every content in the project file is added after the contents of that file and thus will override the value defined earlier. (unless the csproj would contain a condition like <LangVersion Condition="'$(LangVersion)' != ''">…
).
To override any value coming in from the csproj file, you can use a Directory.Build.targets
file which is automatically imported after (!) the project's content which allows you to override values set in the project file.
Upvotes: 9