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

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

Closed
walterlv opened this issue Jun 3, 2019 · 7 comments
Labels
Bug Product bug (most likely) regression status: This issue is a regression from a previous build or release
Milestone

Comments

@walterlv
Copy link
Contributor

walterlv commented Jun 3, 2019

  • .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.
@walterlv
Copy link
Contributor Author

walterlv commented Jun 3, 2019

The minimal reproduction repository is published to GitHub:

@grubioe grubioe added this to the 3.0 milestone Jun 4, 2019
@grubioe grubioe added Bug Product bug (most likely) regression status: This issue is a regression from a previous build or release labels Jun 18, 2019
@vatsan-madhavan
Copy link
Member

@ryalanms Does your current work address this problem?

@ryalanms
Copy link
Member

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

@vatsan-madhavan vatsan-madhavan added the needs-updated-estimate This issue needs an updated estimate label Jun 21, 2019
@walterlv
Copy link
Contributor Author

@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.

@walterlv
Copy link
Contributor Author

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.

@vatsan-madhavan
Copy link
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.

@vatsan-madhavan vatsan-madhavan modified the milestones: 3.0, Preview Jun 21, 2019
@ryalanms
Copy link
Member

This appears to be fixed with #1056.

@grubioe grubioe removed the needs-updated-estimate This issue needs an updated estimate label Jun 25, 2019
@grubioe grubioe modified the milestones: Preview, 3.0 Jun 27, 2019
@grubioe grubioe modified the milestones: 3.0, 5.0 Jul 10, 2019
@arpitmathur arpitmathur assigned arpitmathur and unassigned ryalanms Nov 26, 2019
@arpitmathur arpitmathur removed their assignment Apr 17, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Apr 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Product bug (most likely) regression status: This issue is a regression from a previous build or release
Projects
None yet
Development

No branches or pull requests

5 participants