Skip to content
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

Fix --no-build publishing when axaml compiler is used #16835

Merged
merged 1 commit into from
Sep 5, 2024

Conversation

js6pak
Copy link
Contributor

@js6pak js6pak commented Aug 27, 2024

What does the pull request do?

Fixes dotnet publish --no-build when axaml compiler is used.

What is the current behavior?

The original assembly before axaml compilation is copied resulting in the following crash:
Unhandled exception. Avalonia.Markup.Xaml.XamlLoadException: No precompiled XAML found for AvaloniaApplication1.App, make sure to specify x:Class and include your XAML file as AvaloniaResource

What is the updated/expected behavior with this PR?

The proper assembly is copied over, and the application starts correctly.

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

I've used ComputeResolvedFilesToPublishList because that's where IntermediateAssembly and _DebugSymbolsIntermediatePath are processed.
An alternative solution is prepending InjectAvaloniaXamlOutput to PublishItemsOutputGroupDependsOn Turns out even that won't work because ComputeAndCopyFilesToPublishDirectory would end up calling ComputeResolvedFilesToPublishList before PublishItemsOutputGroup.
Adding PublishItemsOutputGroup to InjectAvaloniaXamlOutput's BeforeTargets won't work because it will run after ComputeResolvedFilesToPublishList.

Repro

rm -rf bin obj && dotnet build -c Release && dotnet publish --no-build && ./bin/Release/net8.0/publish/AvaloniaApplication1

@avaloniaui-bot
Copy link

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

@cla-avalonia
Copy link
Collaborator

cla-avalonia commented Aug 27, 2024

  • All contributors have signed the CLA.

@js6pak
Copy link
Contributor Author

js6pak commented Aug 27, 2024

@cla-avalonia agree

@TomEdwardsEnscape
Copy link
Contributor

LGTM

Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

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

Thank you!

@maxkatz6 maxkatz6 added this pull request to the merge queue Sep 5, 2024
Merged via the queue into AvaloniaUI:master with commit dbbb6d1 Sep 5, 2024
11 checks passed
MattSturgeon added a commit to MattSturgeon/nixpkgs that referenced this pull request Sep 7, 2024
MattSturgeon added a commit to MattSturgeon/nixpkgs that referenced this pull request Sep 8, 2024
Backport AvaloniaUI/Avalonia#16835 to versions
11.1.0 through 11.2.0-beta1

Co-authored-by: Nick Cao <nickcao@nichi.co>
@ahsan136
Copy link

Thank you!

How do I implement this fix? I am having the same issue

@MattSturgeon
Copy link

How do I implement this fix? I am having the same issue

Here's how we backported the fix in nixpkgs: https://github.com/NixOS/nixpkgs/blob/ae8a436bc79e20e05d16f4df99aae01527602f0f/pkgs/build-support/dotnet/fetch-nupkg/overrides.nix#L45-L47

If you're getting Avalonia from nuGet, you can do something similar by substituting or patching build/AvaloniaBuildTasks.targets and buildTransitive/AvaloniaBuildTasks.targets;

replacing 'BeforeTargets="CopyFilesToOutputDirectory;BuiltProjectOutputGroup"'
with 'BeforeTargets="CopyFilesToOutputDirectory;BuiltProjectOutputGroup;ComputeResolvedFilesToPublishList"'.

@ahsan136
Copy link

I made the changes as suggested for nuGet, however after publishing the application I still run into the same exception:
Exception Info: Avalonia.Markup.Xaml.XamlLoadException: No precompiled XAML found for App.App, make sure to specify x:Class and include your XAML file as AvaloniaResource

@MattSturgeon
Copy link

I'm not too familiar with how this works outside of nixpkgs. It sounds like the Avalonia you're patching isn't the one being used after your app is published.

Maybe something like "self contained build" will help?

@ahsan136
Copy link

I added the following but still getting the same error? Also I am on Avalonia version 11.1.3.

	<PropertyGroup>
		<RuntimeIdentifier>win-x86</RuntimeIdentifier>
		<PlatformTarget>x86</PlatformTarget>
		<SelfContained>true</SelfContained>
	</PropertyGroup>

@TomEdwardsEnscape
Copy link
Contributor

You can get the fix by updating to 11.2.0-beta2

@grokys grokys added backported-11.1.x and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported-11.1.x bug customer-priority Issue reported by a customer with a support agreement.
Projects
None yet
8 participants