Repository navigation
Description
Description
I am writing to report an issue encountered when disabling the IncludePackageReferencesDuringMarkupCompilation feature in a WPF project setup. The problem arises during the build process when XAML files are referenced across projects and added as links.
Disabling the IncludePackageReferencesDuringMarkupCompilation feature leads to the following issues:
- When referencing XAML files from another project and adding them as links, the build process fails with error CS1504.
- The generated
g.csfiles from XAML contain incorrect relative file paths in the#pragma checksumdirective, causing the build to fail.
Reproduction Steps
- Create two WPF projects:
- A WPF Library project.
- A WPF Application project.
- In the WPF Library project, add a user control named
MyUserControl. - In the WPF Application project, reference the
MyUserControl.xamlandMyUserControl.xaml.csfiles using the following code:
<ItemGroup>
<Compile Include="..\HalllidanairjelDawearlairnal\MyUserControl.xaml.cs" Link="MyUserControl.xaml.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="..\HalllidanairjelDawearlairnal\MyUserControl.xaml" Link="MyUserControl.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>Disable the IncludePackageReferencesDuringMarkupCompilation feature in the WPF Application project by modifying its .csproj file as shown below:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<IncludePackageReferencesDuringMarkupCompilation>False</IncludePackageReferencesDuringMarkupCompilation>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\HalllidanairjelDawearlairnal\MyUserControl.xaml.cs" Link="MyUserControl.xaml.cs" />
</ItemGroup>
<ItemGroup>
<Page Include="..\HalllidanairjelDawearlairnal\MyUserControl.xaml" Link="MyUserControl.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>You can find my repro project in github
Expected behavior
The build process should correctly handle XAML file references and generate accurate paths in the g.cs files, even with the IncludePackageReferencesDuringMarkupCompilation feature disabled.
I would appreciate your assistance in investigating this issue and providing a resolution or workaround.
Thank you for your attention to this matter.
Actual behavior
With the IncludePackageReferencesDuringMarkupCompilation feature disabled, attempting to build the WPF Application project results in the following error:
obj\Debug\net9.0-windows\MyUserControl.g.cs(59,21,59,41): error CS1504: Cannot open source file "MyUserControl.xaml" -- Could not find file
This error indicates that the generated g.cs file contains an incorrect relative path for MyUserControl.xaml, leading to a build failure.
The first line code content of MyUserControl.g.cs:
#pragma checksum "MyUserControl.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "36731363E365869F8481967B94B2EC18BAB0FBB1"Regression?
No response
Known Workarounds
No response
Impact
No response
Configuration
No response
Other information
Reference:
- .NET 9 SDK WPF build broken with AssemblyName in Directory.Build.props #10068 (comment)
- Cannot use source generator code in xaml file #8128
- IncludePackageReferencesDuringMarkupCompilation causes excluded NuGet targets/props files to be executed #4311
Reference #7556
Activity