0

I have created a NuGet package that contains Native Libraries in two subfolders (amd64 and x86). The NativeLibraries are supposed to be copied into subfolders of the OutputPath, which works. I used the following stackoverflow entry as a guide for creating the package: https://stackoverflow.com/a/30316946/4496150

The NuGet package folder structure looks like this:

  • build
    • amd64
      • DLL1.dll
      • DLL2.dll
    • x86
      • DLL1.dll
      • DLL2.dll
    • packagename.targets

My targets file looks like this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <NativeLibs Include="$(MSBuildThisFileDirectory)**\*.dll" />
    <None Include="@(NativeLibs)">
      <Link>%(RecursiveDir)%(FileName)%(Extension)</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>

However, additionally the files are copied flat into the Outputpath during the build step (msbuild.exe, VS 2019). Since the files in the amd64 and x86 folders are named the same, they overwrite each other.

The crucial build output looks like this:

Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\amd64\DLL1.dll" to "C:\Bin\amd64\DLL1.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\amd64\DLL2.dll" to "C:\Bin\amd64\DLL2.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\x86\DLL1.dll" to "C:\Bin\x86\DLL1.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\x86\DLL2.dll" to "C:\Bin\x86\DLL2.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\amd64\DLL1.dll" to "C:\Bin\DLL1.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\amd64\DLL2.dll" to "C:\Bin\DLL2.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\x86\DLL1.dll" to "C:\Bin\DLL1.dll".
Copying file from "C:\Users\USERNAME\.nuget\packages\PACKAGENAME\1.2.3\build\x86\DLL2.dll" to "C:\Bin\DLL2.dll".

How can I prevent the NativeLibraries from being additionally copied flat to the Output folder?

Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27
MisterGray
  • 329
  • 3
  • 15
  • Did you use a net core lib project or a non-sdk net framework proejct? And is your issue why the DLL1.dlls and DLL2.dlls are copied again into the root output folder? – Sara Liu - MSFT Apr 15 '21 at 03:14
  • Does it help when you set `False` on the `None` item? `None` and `Content` are also considered for assembly resolution and may be considered as local referenced assemblies – Martin Ullrich Apr 15 '21 at 07:49
  • Hi MisterGray, any update about this issue? Please let us know if it works or not. – Sara Liu - MSFT Apr 19 '21 at 01:50
  • Hi @SaraLiu-MSFT Sorry for the delay, I didn't have access to my work computer to test it again. Please see my comment on your solution. – MisterGray Apr 21 '21 at 14:11

1 Answers1

1

I created such nuget package with your guide and did not get the same behavior as you shown.

This is my nupkg:

enter image description here

enter image description here

Not sure whether there is an old cache under your the global cache.

Please try these:

assume that you used a non-sdk project net framework project.

1) first uninstall the nuget package under your project

2) clean nuget caches or delete all files under C:\Users\xxx\.nuget\packages\PACKAGENAME

Also, delete <solution_folder>\packages\PACKAGENAME.1.2.3 folder

3) reinstall the new version of the nuget package again.

Also, check whether your packagename.targets file has other node to affect that.

Sara Liu - MSFT
  • 6,007
  • 1
  • 21
  • 27
  • I can confirm that it works as I initially tried and as you described. However, I still have problems when I add another NuGet package that contains Native Libraries without subfolders. I'll create another question for that though. – MisterGray Apr 21 '21 at 14:13
  • Here is the new question: https://stackoverflow.com/q/67198075/4496150 – MisterGray Apr 21 '21 at 14:41