Skip to content

Cannot use source generator code in xaml file #8128

Open

Description

@ye4241

Description

Cannot use generated code from analyzers in xaml file, it reported missing assembly or reference.

Reproduction Steps

Steps

  1. Create a WPF project with .net6.0-windows
  2. Add <IncludePackageReferencesDuringMarkupCompilation>true</IncludePackageReferencesDuringMarkupCompilation> in csproj
  3. Reference Aigamo.ResXGenerator to generate designer file of resx manually.
  4. Add Resources.resx file, remove Custom Tool of it, add HelloWorld key into resx.
  5. Add textblock to use this string in xaml, <TextBlock Text="{x:Static res:Resources.HelloWorld}" />
  6. Build the project

Error

Target CoreCompile:
1>    xxx\WpfApp2\WpfApp2\obj\Debug\net6.0-windows\MainWindow.g.cs(34,15,34,25): error CS0234: The type or namespace name 'Properties' does not exist in the namespace 'WpfApp2' (are you missing an assembly reference?)

Sample
SamleApplication.zip

Expected behavior

IncludePackageReferencesDuringMarkupCompilation should works for xaml file.
Please include sources from analyzers in CoreCompile target.

Actual behavior

IncludePackageReferencesDuringMarkupCompilation not works in xaml file.

Regression?

No response

Known Workarounds

#3404

Impact

No response

Configuration

No response

Other information

No response

Activity

  1. added
    Investigate
    on Aug 23, 2023
  2. Kuldeep-MS commented on Aug 28, 2023

    @Kuldeep-MS
    Contributor

    @ye4241 - I attempted to recreate the problem using the sample application you provided, but I encountered different errors as shown in the image here:
    image

    Would you be able to verify if the sample application is functioning as intended while I continue my investigation?

  3. ye4241 commented on Aug 28, 2023

    @ye4241
    Author

    @Kuldeep-MS You may need to remove the default Custom Tool for .resx files in .csproj file, as it might have been accidentally added when reopening the project.

    Or just delete below codes to make sure there is no generator of resx file.

    image

    Errors:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Investigate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions