Error CS1504 Due to Disabling IncludePackageReferencesDuringMarkupCompilation
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
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:
1. When referencing XAML files from another project and adding them as links, the build process fails with error CS1504.
2. The generated `g.cs` files from XAML contain incorrect relative file paths in the `#pragma checksum` directive, causing the build to fail.
### Reproduction Steps
1. Create two WPF projects:
- A WPF Library project.
- A WPF Application project.
2. In the WPF Library project, add a user control named `MyUserControl`.
3. In the WPF Application project, reference the `MyUserControl.xaml` and `MyUserControl.xaml.cs` files using the following code:
```xml
MSBuild:Compile
```
Disable the `IncludePackageReferencesDuringMarkupCompilation` feature in the WPF Application project by modifying its `.csproj` file as shown below:
```xml
WinExe
net9.0-windows
enable
enable
true
False
MSBuild:Compile
```
You can find my repro project in [github](https://github.com/lindexi/lindexi_gd/tree/ee493914d4ac77e06bf6ac789ad84a0e8452be76/WPFDemo/TestIncludePackageReferencesDuringMarkupCompilation)
### 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:
```csharp
#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:
- https://github.com/dotnet/wpf/issues/10068#issuecomment-2476304964
- https://github.com/dotnet/wpf/issues/8128
- https://github.com/dotnet/wpf/issues/4311
Reference https://github.com/dotnet/wpf/pull/7556
Contributor guide
Assessment
This issue has not been assessed yet.