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:
<AdditionalFiles Include="**\*.xaml" />
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:
<AdditionalFiles Include="**\*.xaml" Link="%(RecursiveDir)%(Filename)%(Extension)" />
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.
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?
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:
<AdditionalFiles Include="**\*.xaml" />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:
<AdditionalFiles Include="**\*.xaml" Link="%(RecursiveDir)%(Filename)%(Extension)" />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.
At this point I’m not sure what the correct approach is. I need all XAML file paths available for a generator, but without:
i tried to use
Directory.EnumerateFilesbut file I/O banned in generator.what should i do?