Skip to content

When including any Page item via NuGet package props/targets files, all included Compile items will lost. #811

Closed

Description

@walterlv
  • .NET Core Version: 3.0 Preview5
  • Windows version: 10.0.18362.145 (1903)
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes

Problem description:

  1. Build a NuGet package with both XAML and C# files in.
  2. Add Package.targets file into the NuGet package build folder and include the XAML files as Page and C# files as Compile.
  3. When Installing this package, we'll get a compiling error.

Actual behavior:

  1. If we check the compiling message of the CoreCompile target, we'll find that the Compile files we just included are not in the file list.
  2. If we delete all the Page items, the Compile items will come back normal.

Expected behavior:

No Compile file is lost if we include Page items.

Minimal repro:

1st. Build a NuGet package with such a file structure:

- build
    - Walterlv.DemoPackage.targets
+ buildMultiTargeting
+ lib
- src
    - DemoView.xaml
    - DemoView.xaml.cs

In the Walterlv.DemoPackage.targets file, we have such the codes:

<Project>

  <PropertyGroup>
    <MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
  </PropertyGroup>

  <ItemGroup>
    <!-- I use the absolute path to avoid the side effect of the property value evaluation. -->
    <Compile Include="C:\Users\lvyi\.nuget\packages\walterlv.demopackage\0.1.0\src\DemoView.xaml.cs" />
    <Page Include="C:\Users\lvyi\.nuget\packages\walterlv.demopackage\0.1.0\src\DemoView.xaml" />
  </ItemGroup>

</Project>

2nd. When we install this package into another empty WPF project just as the csproj below, we can't compile it correctly.

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Walterlv.DemoPackage" Version="0.1.0" />
  </ItemGroup>

</Project>

3rd. Check the compiling message of the CoreCompile target.

we'll find that the DemoView.xaml.cs file we just included in the NuGet build targets file is lost but we can see the DemoView.g.cs file which is compiled using the DemoView.xaml file.

The Compiling files are:

  • Program.cs
  • C:\Users\lvyi.nuget\packages\walterlv.demopackage\0.1.0\build..\src\DemoView.xaml.cs C:\Users\lvyi\Desktop\Walterlv.Bugs.NuGetPackages\Walterlv.Bugs.NuGetPackages\obj\Debug\net45\DemoView.g.cs
  • "C:\Users\lvyi\AppData\Local\Temp.NETFramework,Version=v4.5.AssemblyAttributes.cs"
  • obj\Debug\net45\Walterlv.Bugs.NuGetPackages.AssemblyInfo.cs

If we delete the Page including line, we'll get such the targets file below:

    <Compile Include="C:\Users\lvyi\.nuget\packages\walterlv.demopackage\0.1.0\src\DemoView.xaml.cs" />
--  <Page Include="C:\Users\lvyi\.nuget\packages\walterlv.demopackage\0.1.0\src\DemoView.xaml" />
  </ItemGroup>

The Compiling files are:

  • Program.cs
  • C:\Users\lvyi\Desktop\Walterlv.Bugs.NuGetPackages\Walterlv.Bugs.NuGetPackages\obj\Debug\net45\DemoView.g.cs
  • C:\Users\lvyi\Desktop\Walterlv.Bugs.NuGetPackages\Walterlv.Bugs.NuGetPackages\obj\Debug\net45\GeneratedInternalTypeHelper.g.cs
  • obj\Debug\net45\Walterlv.Bugs.NuGetPackages_odpvv1kh_wpftmp.AssemblyInfo.cs

Check the compiling message again of the CoreCompile target.

We'll find that the DemoView.xaml.cs file comes back but the DemoView.g.cs file is lost we is expected because we've deleted the xaml file.

Extra.

  1. Nothing works even if we add <Generator>MSBuild:Compile</Generator> for the Page items.
  2. If we rename the Page item into Page2 or any other names, it behaves just like we deleted the Page line. So I can assume that Page item is treated differently.
  3. Resource item works fine even if it is WPF's compiling items. Only Page item has this bug.
  4. If we import the targets file through the Project file or the Directory.Build.targets file but not through NuGet packages, all behaves normal.

Activity

  1. walterlv commented on Jun 3, 2019

    @walterlv
    ContributorAuthor

    The minimal reproduction repository is published to GitHub:

  2. added this to the 3.0 milestone on Jun 4, 2019
  3. added
    Bug
    regression
    on Jun 18, 2019
  4. vatsan-madhavan commented on Jun 20, 2019

    @vatsan-madhavan
    Member

    @ryalanms Does your current work address this problem?

  5. ryalanms commented on Jun 20, 2019

    @ryalanms
    Member

    @walterlv's repro project is compiling with the NuGet restore PBT prototype. It appears to be the same issue.

  6. added
    needs-updated-estimate
    on Jun 21, 2019
  7. walterlv commented on Jun 21, 2019

    @walterlv
    ContributorAuthor

    @ryalanms @vatsan-madhavan The main reason of this issue is that when the GenerateTemporaryTargetAssembly is generating a temporary assembly for the MarkupCompilePass2 XAML compiling, the new temp project named xxx_wpftmp.csproj only collects the ReferencePaths and the generated code only compiled by the MarkupCompilePass1. In my reproduction, my NuGet package also generates code during the compiling but the newly generated code will not be compiled into the temp project.

  8. walterlv commented on Jun 21, 2019

    @walterlv
    ContributorAuthor

    I've hacked into the GenerateTemporaryTargetAssembly task and include my NuGet files before generating temp project and after the MarkupCompilePass1 and it worked. I use the _GeneratedCode private property to fix this issue but it isn't what the SDK want to see.

    My suggestions:

    1. Import all the props and targets that are collected by the NuGet package. This may fix this issue but it may break the purpose of ignoring whole compiling of the temp project (maybe for performance).
    2. Pass newly generated code into the GenerateTemporaryTargetAssembly task.
  9. vatsan-madhavan commented on Jun 21, 2019

    @vatsan-madhavan
    Member

    @ryalanms if that's the case, please move this issue over the Preview milestone so that it can be tracked together.

    @walterlv we are working on a fix. the fix approach will likely run restore on the temp project to generate its own nuget props/targets files, rather than trying to reuse props/targets files belonging to the original project.

  10. modified the milestones: 3.0, Preview on Jun 21, 2019
  11. ryalanms commented on Jun 21, 2019

    @ryalanms
    Member

    This appears to be fixed with #1056.

  12. removed
    needs-updated-estimate
    on Jun 25, 2019
  13. modified the milestones: Preview, 3.0 on Jun 27, 2019
  14. modified the milestones: 3.0, 5.0 on Jul 10, 2019
  15. removed their assignment
    on Apr 17, 2020
  16. ghost locked as resolved and limited conversation to collaborators on Apr 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugregression

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions