-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
The DefineConstants properties for multi targeting builds are a bit confusing, since they are global and not local. This means that if there is a custom -p:DefineConstants=WHATEVER on the command line, the multi targeting constants won't get added.
What I'm asking here is to add a TreatAsLocalProperty="DefineConstants" to Microsoft.NET.Sdk.CSharp.targets, (and possibly other .target / .props files where DefineConstants gets updated), so that it works consistently when the consuming build modifies it via a PropertyGroup as well as via command line args.
Let me elaborate. We have an old non-SDK style solution that we are gradually refactoring into AspNetCore and SDK-style. We were confronted with the build on the CI server failing miserably, because the target framework constants weren't defined during the build (e.g. #if NET462 and #if NETCOREAPP2_2 were not working as expected). Turned out that we had some build configurations passing in a custom DefineConstants property. As this property is global, this line Microsoft.NET.Sdk.CSharp.targets does not work like a non-msbuild expert would would expect from reading it. It took us multiple days of digging through MSBuildBinLog, and collective WTFing, to finally figure out what's going on. Ironically, we did skim over the SDK.CSharp.targets, as it was seemingly not doing what it was supposed to do, but it looked OK at first glance.
Adding to the confusion was the fact that if you add a custom <PropertyGroup><DefineConstants>WHATEVER</DefineConstants></PropertyGroup>, it gets concatenated, and not overridden.
Ideally, it would behave the same way (concatenate the existing value) when it gets passed in via the command line arg.