dotnet / dotnet/roslyn

How to pass files to generator?

Open
#83,545 2 comments 0 reactions 0 assignees View on GitHub
Area-IDE Feature - Source Generators
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

I need to pass all XAML file paths to a generator in my project. Initially, I achieved this by adding the following line to my .csproj file:
`
`
However, after doing this, I noticed that all XAML files were incorrectly assigned the build action as C# analyzer additional files, which broke the normal XAML workflow.

When I tried to add a new XAML file afterward, Visual Studio started throwing the following error:

**“The given key was not present in the dictionary.”**

To work around this, I modified the entry to:

`
`
This fixed the build action issue, but the error still occurs when adding new XAML files.

Next, I changed the include scope to:

`Include="Views\**\*.xaml"
`
With this change, everything appears to work correctly: I can add new XAML files without errors. However, now I see additional linked shortcut versions of XAML files appearing in Solution Explorer, which is very confusing and cluttered.

Image

At this point I’m not sure what the correct approach is. I need all XAML file paths available for a generator, but without:

- breaking Visual Studio project behavior
- causing “key not present in dictionary” errors
- or introducing unwanted linked file duplicates

i tried to use `Directory.EnumerateFiles` but file I/O banned in generator.
what should i do?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.