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

Update to version 3.x breaks Avalonia projects #260

Closed
enegs opened this issue Mar 9, 2023 · 2 comments · Fixed by #268
Closed

Update to version 3.x breaks Avalonia projects #260

enegs opened this issue Mar 9, 2023 · 2 comments · Fixed by #268
Labels

Comments

@enegs
Copy link

enegs commented Mar 9, 2023

Describe the Bug

Updating from 2.x to 3.x breaks Avalonia projects.
App crashes at launch, it seems that xaml content (files?) cannot be loaded.

Steps to Reproduce

  1. Create blank Avalonia .NET Core App
  2. Add GitInfo nugget 3.x
  3. Launch app

Ready to use sample: https://github.com/enegs/GitInfo3UpdateBreaksAvaloniaApp

Expected Behavior

App should load and run.

Exception with Stack Trace

Avalonia.Markup.Xaml.XamlLoadException
HResult=0x80131500
Message=No precompiled XAML found for GitInfo3UpdateBreaksAvaloniaApp.App, make sure to specify x:Class and include your XAML file as AvaloniaResource
Source=Avalonia.Markup.Xaml
StackTrace:
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Object obj) in //src/Markup/Avalonia.Markup.Xaml/AvaloniaXamlLoader.cs:line 26
at GitInfo3UpdateBreaksAvaloniaApp.App.Initialize() in C:\Users\jd\source\repos\GitInfo3UpdateBreaksAvaloniaApp\App.axaml.cs:line 11
at Avalonia.Controls.AppBuilderBase`1.Setup() in /
/src/Avalonia.Controls/AppBuilderBase.cs:line 308
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 208
at GitInfo3UpdateBreaksAvaloniaApp.Program.Main(String[] args) in C:\Users\jd\source\repos\GitInfo3UpdateBreaksAvaloniaApp\Program.cs:line 12

Version Info

GitInfo 3.0.2 or 3.0.4
Avalonia 0.10.18
.NET 6.0 or .NET 7.0

Additional Info

  • No problem with latest 2.3.0 version.
  • Adding <GitVersion>false</GitVersion> does not solve the issue.
@enegs enegs added the bug label Mar 9, 2023
@MrJul
Copy link

MrJul commented Mar 9, 2023

It's not GitInfo that's the problem directly, but rather its dependency ThisAssembly.Constants.

The InjectConstantAdditionalFiles target depends on PrepareResourceNames.
This causes it to run much earlier in the build pipeline that normally, causing the issue. The EmbeddedResource added by Avalonia is only added after, doesn't get a target path and thus isn't embedded.

I'm not familiar with ThisAssembly targets so I don't know why this dependency is here. Usually extra files should be added before AssignTargetPaths (called by PrepareResourceNames) runs to get correct paths (here it's not a Content or EmbeddedResource so it doesn't matter).

The theoretical fix here should be to remove this dependency, as running before PrepareForBuild should be sufficient. In practice, I know from experience that finding the right MSBuild target to anchor to can cause some serious headaches :)

This could also be fixed on the Avalonia side by depending directly on AssignTargetPaths. However, I think ThisAssembly making AssignTargetPaths runs so soon might cause issues in other packages.

kzu added a commit to devlooped/ThisAssembly that referenced this issue Mar 22, 2023
When we add items/propeties that need to be visible to the generators, we only really need to run before the editorconfig is emitted, and no earlier. This happens right before compilation, so it's a safe late-stage target to depend on.

We cannot run later since that would mean outdated info to the generator, but this should avoid early-run issues such as devlooped/GitInfo#260.
kzu added a commit to devlooped/ThisAssembly that referenced this issue Mar 22, 2023
When we add items/propeties that need to be visible to the generators, we only really need to run before the editorconfig is emitted, and no earlier. This happens right before compilation, so it's a safe late-stage target to depend on.

We cannot run later since that would mean outdated info to the generator, but this should avoid early-run issues such as devlooped/GitInfo#260.
kzu added a commit to devlooped/ThisAssembly that referenced this issue Mar 22, 2023
When we add items/propeties that need to be visible to the generators, we only really need to run before the editorconfig is emitted, and no earlier. This happens right before compilation, so it's a safe late-stage target to depend on.

We cannot run later since that would mean outdated info to the generator, but this should avoid early-run issues such as devlooped/GitInfo#260.
@kzu kzu closed this as completed in #268 Mar 22, 2023
@kzu
Copy link
Member

kzu commented Mar 22, 2023

Thanks a lot @MrJul for the analysis! It was key to finding out a quick fix :)

@devlooped devlooped locked and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants