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

Source Generated Keys Dont Work Via NuGet #27

Closed
Axemasta opened this issue Aug 15, 2023 · 3 comments
Closed

Source Generated Keys Dont Work Via NuGet #27

Axemasta opened this issue Aug 15, 2023 · 3 comments

Comments

@Axemasta
Copy link
Owner

The sample project works when referencing the source generator project directly however it fails to work when referencing via nuget.

Error XFC0101: x:Static: unable to find a public -- or accessible internal -- static field, static property, const or enum value named "MocaleTitle" in "keys:TranslationKeys". (XFC0101) (Mocale.Samples) XamlC

Viewing the generated class in visual studio shows the correctly generated class, interestingly at runtime (after removing references) the type exists but has no values.

This is probably just to do with the compilation order and i will need to investigate adding targets to the generator so that it runs at the right time during compilation.

@Axemasta
Copy link
Owner Author

Looks like this is to do with caching, i noticed this issue when installing Mocale in an external codebase which had never been setup before.

Whilst visual studio was open, deleting bin / obj, restoring and building did not work, I believe this is because source generators get cached by visual studio, the solution was:

  • Setup library (reference json files as AdditionalFiles)
  • Close visual studio
  • Delete all bin / obj folders
  • Open visual studio
  • Restore & build

If anyone experiences this issue, please try these steps otherwise we can reopen this issue and investigate further

@Axemasta
Copy link
Owner Author

Reopening as this issue suddenly emerged after i closed this issue... 🤦‍♂️

On windows i get the following message:

Severity	Code	Description	Project	File	Line	Suppression State	Detail Description
Warning	CS8785	Generator 'LocalizationKeySourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'FileNotFoundException' with message 'Could not load file or assembly 'System.Text.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified.'	Mocale.Samples (net7.0-android)	C:\Dev\GitHub\Mocale\samples\Mocale.Samples\CSC	1	Active	Generator threw the following exception:
'{0}'.

This is potentially an authoring issue with the generator

@Axemasta
Copy link
Owner Author

Here is a sample that appears to be working, interestingly my work project doesnt work but file -> new projects do, hopefully this is a caching issue and not a compatibility issue.

Closing issue for now, hopefully the cache expires and i get a working project. If i find anything I will reopen this issue

Working Generator Sample.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant