Repository navigation
Description
- .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:
- Build a NuGet package with both XAML and C# files in.
- Add Package.targets file into the NuGet package build folder and include the XAML files as
Pageand C# files asCompile. - When Installing this package, we'll get a compiling error.
Actual behavior:
- If we check the compiling message of the
CoreCompiletarget, we'll find that theCompilefiles we just included are not in the file list. - If we delete all the
Pageitems, theCompileitems 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.
- Nothing works even if we add
<Generator>MSBuild:Compile</Generator>for thePageitems. - If we rename the
Pageitem intoPage2or any other names, it behaves just like we deleted thePageline. So I can assume thatPageitem is treated differently. Resourceitem works fine even if it is WPF's compiling items. OnlyPageitem has this bug.- 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
walterlv commentedon Jun 3, 2019
The minimal reproduction repository is published to GitHub:
vatsan-madhavan commentedon Jun 20, 2019
@ryalanms Does your current work address this problem?
ryalanms commentedon Jun 20, 2019
@walterlv's repro project is compiling with the NuGet restore PBT prototype. It appears to be the same issue.
walterlv commentedon Jun 21, 2019
@ryalanms @vatsan-madhavan The main reason of this issue is that when the
GenerateTemporaryTargetAssemblyis generating a temporary assembly for theMarkupCompilePass2XAML compiling, the new temp project namedxxx_wpftmp.csprojonly collects theReferencePaths and the generated code only compiled by theMarkupCompilePass1. 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 commentedon Jun 21, 2019
I've hacked into the
GenerateTemporaryTargetAssemblytask and include my NuGet files before generating temp project and after theMarkupCompilePass1and it worked. I use the_GeneratedCodeprivate property to fix this issue but it isn't what the SDK want to see.My suggestions:
GenerateTemporaryTargetAssemblytask.vatsan-madhavan commentedon Jun 21, 2019
@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
restoreon the temp project to generate its own nuget props/targets files, rather than trying to reuse props/targets files belonging to the original project.ryalanms commentedon Jun 21, 2019
This appears to be fixed with #1056.