Skip to content

Run GenerateAvaloniaResources before _InjectAvaloniaAdditionalFiles - #22175

Merged
MrJul merged 1 commit into
AvaloniaUI:mainfrom
Evan260:fix-inject-additional-files-ordering
Sep 11, 2026
Merged

MrJul merged 1 commit into
AvaloniaUI:mainfrom
Evan260:fix-inject-additional-files-ordering

Conversation

@Evan260

@Evan260 Evan260 commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

What does the pull request do?

Makes _InjectAvaloniaAdditionalFiles depend on GenerateAvaloniaResources, so AvaloniaResourcePaths is always complete.

What is the current behavior?

GenerateAvaloniaResources adds AvaloniaXaml items to AvaloniaResource. _InjectAvaloniaAdditionalFiles reads AvaloniaResource to build AvaloniaResourcePaths. Nothing orders the two, so the result depends on which target MSBuild happens to schedule first.

Using samples/AppWithoutLifetime on main:

> dotnet build samples/AppWithoutLifetime -t:Build -getproperty:AvaloniaResourcePaths
build\Assets\icon.ico,samples\AppWithoutLifetime\App.axaml,samples\AppWithoutLifetime\MainWindow.axaml,samples\AppWithoutLifetime\Sub.axaml

> dotnet build samples/AppWithoutLifetime -t:Compile -getproperty:AvaloniaResourcePaths
build\Assets\icon.ico

The three .axaml files are missing in the second case, so source generators using the property see an incomplete list.

Only affects projects whose XAML comes through AvaloniaXaml, which is the default for .axaml. Projects that put files straight into AvaloniaResource were never affected, which is why most samples in this repo don't show it.

What is the updated/expected behavior with this PR?

Both commands return the full list.

How was the solution implemented (if it's not obvious)?

Added DependsOnTargets="GenerateAvaloniaResources", as suggested in the issue. GenerateAvaloniaResources depends on AddAvaloniaResources;ResolveReferences;_GenerateAvaloniaResourcesDependencyCache, so there's no cycle.

On the side effects @timunie asked about

GenerateAvaloniaResources now runs whenever _InjectAvaloniaAdditionalFiles does, including design-time builds. As far as I can tell that's harmless:

  • Both a .axaml and a .xaml sample build clean.
  • dotnet build -t:GenerateMSBuildEditorConfigFile -p:DesignTimeBuild=true succeeds.
  • The target is incremental, so repeat builds log Skipping target "GenerateAvaloniaResources" because all output files are up-to-date. It isn't redoing work in the IDE.

Checklist

No test, since this is target ordering and I couldn't find a harness for it. The two commands above are the check.

Breaking changes

None.

Fixed issues

Fixes #21945

GenerateAvaloniaResources adds AvaloniaXaml items to AvaloniaResource, which
_InjectAvaloniaAdditionalFiles then reads to build AvaloniaResourcePaths.
Nothing ordered the two, so the property could be built from a partial list
depending on which target MSBuild scheduled first.
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.2.999-cibuild0069602-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added bug area-infrastructure Issues related to CI/tooling infrastructur backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 8, 2026

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change makes sense. In a normal (non-design) build, GenerateAvaloniaResources has already run so this doesn't affect the standard path.

LGTM!

@MrJul
MrJul added this pull request to the merge queue Sep 11, 2026
Merged via the queue into AvaloniaUI:main with commit cb3f93b Sep 11, 2026
11 checks passed
MrJul pushed a commit to MrJul/Avalonia that referenced this pull request Sep 22, 2026
…valoniaUI#22175)

GenerateAvaloniaResources adds AvaloniaXaml items to AvaloniaResource, which
_InjectAvaloniaAdditionalFiles then reads to build AvaloniaResourcePaths.
Nothing ordered the two, so the property could be built from a partial list
depending on which target MSBuild scheduled first.
@MrJul MrJul added backported-12.1.x and removed backport-candidate-12.1.x Consider this PR for backporting to 12.1 branch labels Sep 22, 2026
@Evan260
Evan260 deleted the fix-inject-additional-files-ordering branch September 23, 2026 00:34
grokys pushed a commit to Evan260/Avalonia that referenced this pull request Oct 7, 2026
…valoniaUI#22175)

GenerateAvaloniaResources adds AvaloniaXaml items to AvaloniaResource, which
_InjectAvaloniaAdditionalFiles then reads to build AvaloniaResourcePaths.
Nothing ordered the two, so the property could be built from a partial list
depending on which target MSBuild scheduled first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-infrastructure Issues related to CI/tooling infrastructur backported-12.1.x bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect order of execution of MSBuild targets _InjectAvaloniaAdditionalFiles and GenerateAvaloniaResources.

3 participants