Skip to content

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

Closed
@timothylcooke

Description

@timothylcooke

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions