Compiler cannot copy NuGet package DLL from WPF library to WPF program

74 views Asked by At

I have a very simple setup with two WPF projects in Visual Studio 2022: a WPF application and a WPF library.

Both projects are extremely simple - they contain only a simple empty WPF Window each and when the program starts it opens both. That works.

Then I add a reference to WebView2 in the library and include a WebView2 browser in the library window. This also works fine.

Now I also want to include a video feed and add LibVLCSharp.WPF to the library. Then I include a video player in the library window. This also works fine - I can show video and web side by side.

In my real application I need to reference .NET target framework "net6.0-windows10.0.18362.0" instead of "net6.0-windows". So I change that in both project files.

At this point I get the following error:

NETSDK1082: There was no runtime pack for Microsoft.WindowsDesktop.App.WPF available for the specified RuntimeIdentifier 'win10-arm'.

It seems to be caused by VLC that does not work on WIN10-ARM.

Now I reduce the targets to Windows only by adding this to the project files:

<RuntimeIdentifiers>win10-x64;win10-x86;win10-arm64</RuntimeIdentifiers>

... and now the compiler fails in a way I cannot fix:

2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5198,5): error MSB3030: Could not copy the file "C:\Work\WpfApp1\WpfLibrary1\bin\Debug\net6.0-windows10.0.18362.0\WpfLibrary1\runtimes\win-x64\native\WebView2Loader.dll" because it was not found.
2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5198,5): error MSB3030: Could not copy the file "C:\Work\WpfApp1\WpfLibrary1\bin\Debug\net6.0-windows10.0.18362.0\WpfLibrary1\runtimes\win-arm64\native\WebView2Loader.dll" because it was not found.
2>C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5198,5): error MSB3030: Could not copy the file "C:\Work\WpfApp1\WpfLibrary1\bin\Debug\net6.0-windows10.0.18362.0\WpfLibrary1\runtimes\win-x86\native\WebView2Loader.dll" because it was not found.

For some reason it cannot copy WebView2Loader.dll from the library project to the main project.

Looking closer, it seems to copy from the wrong source. It looks for:

C:\Work\WpfApp1\WpfLibrary1\bin\Debug\net6.0-windows10.0.18362.0\WpfLibrary1\runtimes\win-x64\native\WebView2Loader.dll

But the file is located in:

C:\Work\WpfApp1\WpfLibrary1\bin\Debug\net6.0-windows10.0.18362.0\runtimes\win-x64\native\WebView2Loader.dll

For some odd reason the compiler tries to copy from "...\WpfLibrary1\runtimes" when it should be "...\runtimes" - it is only that additional "WpfLibrary1" that results in the error.

Question: Can anyone tell my why this happens - and maybe what I need to do to fix it?

Edits:

  • The WebView2 files are actually copied to the main application directory by some other step of the compilation process.

Sources

WpfLibrary1.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0-windows10.0.18362.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64;win10-x86;win10-arm64</RuntimeIdentifiers>
    <Nullable>enable</Nullable>
    <UseWPF>true</UseWPF>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="LibVLCSharp.WPF" Version="3.8.2" />
    <PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2151.40" />    
  </ItemGroup>
  
</Project>

WpfApp1.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.18362.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64;win10-x86;win10-arm64</RuntimeIdentifiers>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\WpfLibrary1\WpfLibrary1.csproj" />
  </ItemGroup>

</Project>
0

There are 0 answers