简体   繁体   中英

csproj LangVersion property is overriding any imported project

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM