A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
Hi @Shreyans Yadav ,
Thanks for reaching out.
Is net10.0-windows a valid target framework, or should I downgrade to net8.0-windows?
.NET 10 is supported for WPF. You can try downgrading to .NET 8 temporarily to see if the issue is related to .NET 10, but it’s not required.
Is there a MSBuild flag or project setting that could be causing this?
I looked at your repository, and I don’t see any explicit flag or project setting that would directly cause both .g.cs and .g.i.cs to be compiled.
I suspect the issue could be caused by one of these scenarios:
- Visual Studio’s design-time builds for IntelliSense sometimes don’t fully separate intermediate files from the final compilation, which can leave both
.g.csand.g.i.csin the compile list. - MSBuild caches build state for performance. Even after cleaning
bin/obj, corrupted cache data can persist. The MSBuild incremental builds documentation explains how file lists are cached. - Certain WPF build targets may add generated files to compilation in a way that bypasses normal exclusion logic, especially if custom targets are used or run at the wrong point in the build pipeline.
You could try a more aggressive method to remove the generated files from the compile list:
<Target Name="RemoveIntermediateGeneratedFiles" AfterTargets="MarkupCompilePass1;MarkupCompilePass2" BeforeTargets="CoreCompile">
<ItemGroup>
<Compile Remove="**\*.g.i.cs" />
<FileWrites Remove="**\*.g.i.cs" />
</ItemGroup>
<Message Text="Removed intermediate .g.i.cs files from compilation" Importance="high" />
</Target>
After adding this, make sure to fully clean your solution (delete bin and obj folders) and rebuild, ensures any cached intermediate state is cleared and prevents duplicate definitions from being compiled.
Hope this helps! If my answer was helpful - kindly follow the instructions here so others with the same problem can benefit as well.