-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'AddImplicitDefineConstants' runs too late, and defines are missing when 'XamlPreCompile' runs, causing build failures #43908
Comments
@rainersigwald Would it be less risky to have XamlPreCompile add DependsOnTarget="AddImplicitDefineConstants"? I'm not sure the side effects in msbuild ordering of doing that. Both Targets are set to runtime BeforeTargets CoreCompile today and I want to ensure they run in the right order. |
Hmm. In general I think I prefer hooking |
Just for my own understanding, what's the difference in practice between:
I'm not too familiar with all the specific nuance there to have a strong preference here. Whichever you think is best 😅 cc. @manodasanW @jlaanstra thoughts? |
Hey @rainersigwald! Just circling back on this, should I go ahead and make a PR applying your suggestion then? 🙂
I mean this. |
I think that makes sense.
It's very complicated and there's not usually a really clear answer. Most of the core targets use DependsOnTargets because that was the only option available in MSBuild v1. It has some advantages: implicit ordering in the expression (why, for example, BeforeBuild comes before CoreBuild comes before AfterBuild: they're defined that way in BuildDependsOn), ignorability, every doc knows this. And it has some disadvantages: ignorability, accidental overwrite-instead-of-append, and the biggie requires the target to have a DependsOn with a property which keeps it from being useful for many extension cases.
In general I prefer |
Thank you so much for the additional context! I opened #44695 with the suggested change 🙂 |
@rainersigwald @Sergio0694 I don't see how BeforeCompile is guaranteed to run before XamlPreCompile target, so I don't understand how this fix works? XamlPreCompile is injected into PrepareResourcesDependsOn and so runs before PrepareResources. BeforeCompile is part of CompileDependsOn and so runs before Compile. However in CoreBuildDependsOn, PrepareResources is sequenced before Compile, which suggests that BeforeCompile would still run after XamlPreCompile and I have binlogs that suggest that's indeed happening :). |
That analysis makes sense to me. We can switch to |
Describe the bug
WinUI 3 and UWP apps (perhaps WPF/MAUI ones too?) use the XamlPreCompile task defined in the .NET SDK, which creates the intermediate .dll necessary for XAML compilation. The AddImplicitDefineConstants target runs before 'CoreCompile', but this seems to be too late and after 'XamlPreCompile' has already run. This causes the intermediate XAML build to not see the
_OR_GREATER
defines, meaning it will fail when those are used to exclude incompatible code, and resulting in very weird errors for someone looking at the IDE (which will show the code as being completely fine).I hit this while migrating the Microsoft Store to .NET 9.
Can we make this target use
BeforeTargets="BeforeCompile"
or something, to address this?To Reproduce
Create a WinUI 3 or UWP .NET 9 app with the following code behind:
Expected result
Should build as expected and match the behavior in the IDE.
Actual result
Further technical details
The text was updated successfully, but these errors were encountered: