feat: Targets with constants moved to an earlier stage.
GitHub Issue (If applicable): closes # According this discussion: https://github.com/unoplatform/uno/discussions/9145 The first PR for this, while fixing the name collision, didn't fix the availability of the constants and led to new research.
PR Type
What kind of change does this PR introduce?
Feature
What is the current behavior?
At the moment, constants are added after the .editorconfig file with visible properties is generated, which generators use to access values. Here is the relevant code that shows which Targets are executed and in what order to allow generators to access properties.
https://github.com/dotnet/roslyn/blob/1c3cdb0b85a8496a8f5108faab046924360b6017/src/Compilers/Core/MSBuildTask/Microsoft.Managed.Core.targets#L155-L196
Based on this, I believe that the optimal place to add constants would be AfterTargets="PrepareForBuild". This also applies to other projects - https://github.com/dotnet/ef6tools/blob/c9988fc28258290118e60dc6d9ccb3fe8c6073d6/setup/wix/EFToolsWillowMsi.wixproj#L77 Generators that rely on these constants will need to use code like this:
<Target Name="CreateDefineConstants" BeforeTargets="GenerateMSBuildEditorConfigFileShouldRun;GenerateMSBuildEditorConfigFileCore">
<PropertyGroup>
<Generator_DefineConstants>$(DefineConstants.Replace(';',','))</Generator_DefineConstants>
</PropertyGroup>
</Target>
What is the new behavior?
Targets are run at an earlier stage. In addition, the association of properties has been simplified, and duplication of constants in runtime projects due to the reuse of UnoDefineConstants has been fixed. This output is given by this target in the Skia.WPF project:
<Target Name="Test" BeforeTargets="CoreCompile">
<Message Importance="high" Text="Test $(DefineConstants)"/>
</Target>
1>Test TRACE;HAS_UNO;HAS_WINUI;HAS_UNO_WINUI;RELEASE;NET;NET6_0;NETCOREAPP;UNO_REFERENCE_API;HAS_UNO_SKIA;HAS_UNO_SKIA_WPF;UNO_REFERENCE_API;HAS_UNO_SKIA;HAS_UNO_SKIA_WPF;HAS_UNO;HAS_UNO_WINUI;UNO_HAS_FRAMEWORKELEMENT_MEASUREOVERRIDE;UNO_HAS_NO_IDEPENDENCYOBJECT;UNO_REFERENCE_API
PR Checklist
Please check if your PR fulfills the following requirements:
- [ ] Docs have been added/updated which fit documentation template (for bug fixes / features)
- [ ] Unit Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Validated PR
Screenshots Compare Test Runresults. - [x] Contains NO breaking changes
- [ ] Associated with an issue (GitHub or internal) and uses the automatic close keywords.
- [x] Commits must be following the Conventional Commits specification.
Other information
Internal Issue (If applicable):
I confirm that the generator is able to see constants since version 4.5.0-dev.523