microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.36k stars 678 forks source link

NuGet package lib folder content is not copied to output path of Packaged WinUI 3 apps #6429

Open dahovey opened 2 years ago

dahovey commented 2 years ago

Describe the bug

When a NuGet package includes additional files in the lib folder, these files are not copied to the OutputPath of a Packaged WinUI 3 application, but additional files in the lib folder are copied to output path if the project is a Class Library for WinUI 3. In order to get the additional files to be copied to the output of the Packaged app, a class library is needed and a project reference is required from the Packaged app to the Class Library.

In my case I am trying to use FontAwesome5 version 2.1.6 which includes support for WinUI 3. See screenshot below of NuGet package structure.

Steps to reproduce the bug

  1. Create WinUI 3 Packaged app for Desktop using VS2022 project templates.
  2. Add ProjectReference to FontAwesome5 version 2.1.6
  3. Build project
  4. Open output folder in File Explorer and observe there is not FontAwesome5 folder within output.

What works:

  1. Create WinUI 3 ClassLibrary project using VS2022 project templates.
  2. Add ProjectReference to FontAwesome5 version 2.1.6
  3. Build project
  4. Open output folder in File Explorer and observe there IS FontAwesome5 folder within output.

Expected behavior

Additional files within NuGet package should be copied to output regardless of project type.

Screenshots

image

NuGet package version

WinUI 3 - Windows App SDK 1.0 (If you're seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

Device form factor

Desktop

Windows version

May 2020 Update (19041)

Additional context

No response

dahovey commented 2 years ago

In addition to above, when I create a control library NuGet package that depends on FontAwesome and other packages I receive the following errors:

1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "C:\Users\dahov\.nuget\packages\controlLibrary.winui\0.4.155\lib\net6.0-windows10.0.19041\controlLibrary.WinUI\runtimes\win-arm64\native\WebView2Loader.dll" because it was not found.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "C:\Users\dahov\.nuget\packages\controlLibrary.winui\0.4.155\lib\net6.0-windows10.0.19041\FontAwesome5.WinUI\Fonts\Font Awesome 5 Brands-Regular-400.otf" because it was not found.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "C:\Users\dahov\.nuget\packages\controlLibrary.winui\0.4.155\lib\net6.0-windows10.0.19041\controlLibrary.WinUI\runtimes\win-x86\native\WebView2Loader.dll" because it was not found.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "C:\Users\dahov\.nuget\packages\controlLibrary.winui\0.4.155\lib\net6.0-windows10.0.19041\controlLibrary.WinUI\runtimes\win-x64\native\WebView2Loader.dll" because it was not found.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "C:\Users\dahov\.nuget\packages\controlLibrary.winui\0.4.155\lib\net6.0-windows10.0.19041\FontAwesome5.WinUI\Fonts\Font Awesome 5 Free-Regular-400.otf" because it was not found.
1>C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5100,5): error MSB3030: Could not copy the file "C:\Users\dahov\.nuget\packages\controlLibrary.winui\0.4.155\lib\net6.0-windows10.0.19041\FontAwesome5.WinUI\Fonts\Font Awesome 5 Free-Solid-900.otf" because it was not found.

In this case the FontAwesome5 library includes the Font assets in its own package, but the build is expecting the assets to be included in the control library package.

StephenLPeters commented 2 years ago

@evelynwu-msft FYI

jeromelaban commented 2 years ago

I can confirm this is still not working as of WinAppSDK 1.2.220930.4-preview2. This is caused by this piece in the targets and props files:

1.2.220930.4-preview2\buildTransitive\MrtCore.targets

  <!-- We want MRT Core to NOT be used in WAP or UWP projects. Instead, we want the in-box PRI generation tooling to be used. -->
  <PropertyGroup>
    <EnableCoreMrtTooling Condition="'$(EnableCoreMrtTooling)'=='' and '$(WindowsAppContainer)'!='true' and '$(MSBuildProjectExtension)' != '.wapproj'">true</EnableCoreMrtTooling>
  </PropertyGroup>

1.2.220930.4-preview2\buildTransitive\Microsoft.Build.Msix.Common.props

    <!-- We are currently incompatible with the MRT Core tooling (conflicts due to duplicated,
         but not identical, logic and race conditions that depend on order of Nuget imports). For now
         we will disable the MRT Core tooling with an eye on resolving the incompatibilities once we
         share a repo. Tracked by http://task.ms/31928041-->
    <EnablePriGenTooling>false</EnablePriGenTooling>
    <EnableCoreMrtTooling>false</EnableCoreMrtTooling>

Running unpackaged enables EnablePriGenTooling, which in turn enables AddPriPayloadFilesToCopyToOutputDirectoryItems which properly extracts the files from the imported NuGet pri files and places the assets in the output layout.

This is causing issues for library authors that need to include assets, and forces app developers to run unpackaged.

michael-hawker commented 1 year ago

Bumping, based on https://github.com/microsoft/microsoft-ui-xaml/discussions/8638

@bpulliam there's a number of issues that have suggested fixes, solid repros, or are regressions. Would be great to have a marker for those as the team triages to bubble some of the low-hanging fruit up to get some easy wins?

kjean667 commented 4 weeks ago

Still not working in WindowsAppSDK 1.6.240923002.

The problem is now even worse in 1.6 since an indirect reference through a second wrapper library does not work for the decoupled WebView2 versioning made in 1.6 (see https://github.com/microsoft/WindowsAppSDK/issues/4807 and https://github.com/MicrosoftEdge/WebView2Feedback/issues/4837). When trying to compile the wrapper library that reference a nuget package that references WindowsAppSDK 1.6.240923002 it produces the following compile error:

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5321,5): error MSB3030: Could not copy the file "C:\Users\my-user\.nuget\packages\myuilibrary\1.2.1\lib\net8.0-windows10.0.22621\MyUILibrary\runtimes\win-x64\native\WebView2Loader.dll" because it was not found.

The compile error only appears when referencing the nuget package in a library, which makes this bug (#6429) important to solve again.