Skip to content

Error CS1504 Due to Disabling IncludePackageReferencesDuringMarkupCompilation #10093

Open

Description

@lindexi

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:
  <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:

Reference #7556

Activity

  1. added
    Investigate
    on Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Investigate

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions