0
votes

Problem: Top level project references MyLibrary nuget which references several vendor.dll files. Vendor.dll files should be able to be referenced by top level project when MyLibrary nuget package is added to top level project but they are not.

When I run the top level project I receive this error:

FileNotFoundException: Could not load file or assembly 'Vendor.A, Culture=neutral, PublicKeyToken=b88d1754d700e49a'. The system cannot find the file specified.

Vendor .dll files are not copied to bin folder.

I hope to find a resolution to this problem that does not require me to create a .nuspec file.

Structure of generated MyLibrary nuget package (observed with Nuget package explorer):

lib
    net5.0-windows
        Vendor.a.dll
        Vendor.b.dll
    
    net5.0-windows7.0
        MyLibrary.dll
        

I do not understand where net5.0-windows7.0 comes from. It does not exist in TFM list referenced below. Also, if net5.0-windows7.0 is for some reason necessary, why does MyLibrary.dll exist there but not the .dlls it depends on?

Looking at the package from within Visual Studio 2019 it appears as follows (vendor dlls do not appear):

Packages
    MyLibrary
        Compile Time Assemblies
            MyLibrary.dll

MyLibrary.csproj:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
  <PropertyGroup>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
  </PropertyGroup>

  <PropertyGroup>
    <AssemblyVersion>1.0.0.1</AssemblyVersion>
    <FileVersion>1.0.0.1</FileVersion>
    <Version>1.0.0.3</Version>
  </PropertyGroup>
  

  <ItemGroup>
    <Content Include="$(OutputPath)\Vendor.*.dll">
      <Pack>true</Pack>
      <PackagePath>lib\$(TargetFramework)</PackagePath>
    </Content>
  </ItemGroup>
  
  
  <ItemGroup>
    <Reference Include="Vendor.a">
      <HintPath>VendorLib\Vendor.a.dll</HintPath>
    </Reference>
    <Reference Include="Vendor.b">
      <HintPath>VendorLib\Vendor.b.dll</HintPath>
    </Reference>
  </ItemGroup>

TopLevel.csproj

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

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net5.0-windows</TargetFramework>
  <UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="MyLibrary" Version="1.0.0.3" />
</ItemGroup>

Target Framework Monikers

Similar question

Similar question requiring nuspec

Similar question requiring nuspec

Possibly related issue

1

1 Answers

1
votes

I also found an issue about this strange behavior and still did not know where the net5.0-windows7.0 from. Since the issue is still open and the Team does not know it is normal or a strange issue, as my opinion, net5.0-windows7.0 is the special version for wpf project's frameowork of nuget, so you should pack your dlls into such folder of nupkg.

Although this is not the best function, but is a workaround now. You can keep tracking the issue to get the explanation from the Product Team.

Or try my suggestions:

function one

1) change the targetframwork of your nuget project to

<TargetFramework>net5.0-windows7.0</TargetFramework>

As the Team said, net5.0-windows is the same as net5.0-windows7.0. However, they treat them differently in terms of packaging into nuget.

function two

2) still use <TargetFramework>net5.0-windows</TargetFramework>.

change this to:

<ItemGroup>
    <Content Include="$(OutputPath)\Vendor.*.dll">
        <Pack>true</Pack>
        <PackagePath>lib\$(TargetFramework)7.0</PackagePath>
    </Content>
</ItemGroup>

Besides, when you finish packing nuget project, please delete nuget caches first or delete all files under C:\Users\xxx\.nuget\packages, then install the new release version of the nuget package into the main project.

enter image description here

vendor is my custom nuget project name.