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

[Bug]: Legacy MSBuild projects sometimes fail to build #144

Open
timothylcooke opened this issue Dec 11, 2024 · 3 comments
Open

[Bug]: Legacy MSBuild projects sometimes fail to build #144

timothylcooke opened this issue Dec 11, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@timothylcooke
Copy link

timothylcooke commented Dec 11, 2024

Describe the bug 🐞

By adding a Window with a namespace definition in an SDK-style .NET Framework WPF application, we can essentially prevent SourceGenerators from generating code. The IDE makes it look like everything is fine: you can navigate to the generated source file for properties generated by the [ReactiveUI.SourceGenerators.ReactiveAttribute], but the project fails to compile:

error CS0234: The type or namespace name 'SourceGenerators' does not exist in the namespace 'ReactiveUI' (are you missing an assembly reference?)

Step to reproduce

This project is a minimal reproduction. Initial commit b27e435 builds just fine in both a legacy and sdk-style project. a845b4a adds an xmlns:local definition to XAML. Once that namespace is added, the legacy application no longer compiles (though the SDK-style project continues to compile).

Reproduction repository

https://github.com/timothylcooke/SourceGeneratorIssue

Expected behavior

The project should compile

Screenshots 🖼️

No response

IDE

No response

Operating system

Windows 11 23H2

Version

Visual Studio 17.12.3

Device

No response

ReactiveUI Version

2.0.17

Additional information ℹ️

It's unclear if this is even your bug, or if it's an issue in msbuild.

I have a legacy WPF application deployed with ClickOnce, so I can't switch to an SDK-style project without a whole lot of headache. While ReactiveUI.Fody works fine, I'd like to start using ReactiveUI.SourceGenerators.

Adding local namespaces in XAML is a very common thing in WPF that I can't just avoid doing. The best workaround I have is to move any VM classes to a library.

If you remove all references to ReactiveAttribute to get the project to compile, you can access the type via reflection: var reactiveAttributeTypeViaReflection = GetType().Assembly.GetType("ReactiveUI.SourceGenerators.ReactiveAttribute"); So, it seems like it's an issue with the order of build events: it seems that the generated files are being added after the static files are built, so any references from static files to generated types fail to compile because the types haven't been generated yet.

@timothylcooke timothylcooke added the bug Something isn't working label Dec 11, 2024
@timothylcooke timothylcooke changed the title [Bug]: Legacy MSBuild projects fail to build [Bug]: Legacy MSBuild projects sometimes fail to build Dec 11, 2024
@timothylcooke
Copy link
Author

I just saw in the README that for net481, you're supposed to use Polyfill or PolySharp -- not sure how I missed that before. I added a polysharp branch to the repro where I use PolySharp instead of my own hack. The behavior is unchanged.

Polyfill does not support legacy csproj files.

@glennawatson
Copy link
Contributor

I'm a bit behind on a lot of maintenance stuff in regards to this project and @ChrisPulman is out til christmas.

There can be issues with source generator relying on source generators. I know they moved some of the xaml into a generated based context, not sure if they are using source generators to do.

@glennawatson
Copy link
Contributor

Usually the way I've solved source generator relying on source generator issues is to move into separate projects the source code so only one generator happens at any one time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants