Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error CS1504 Due to Disabling IncludePackageReferencesDuringMarkupCompilation #10093

Open
lindexi opened this issue Nov 19, 2024 · 0 comments
Open
Labels
Investigate Requires further investigation by the WPF team.

Comments

@lindexi
Copy link
Member

lindexi commented Nov 19, 2024

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

@harshit7962 harshit7962 added the Investigate Requires further investigation by the WPF team. label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Investigate Requires further investigation by the WPF team.
Projects
None yet
Development

No branches or pull requests

2 participants