1

I need to use native c libraries in my library(that supports several Core TFs and .net framework) which is published via nuget. I configured it via .csproj file and runtimes folder. But I noticed that when I consume my NuGet via dotnet add package .. in some cases, the native libraries are not copied into the expected folder after consuming, however when I use the VS UI Nuget package manager->Manage Nuget Packages for Solution, all files are placed into correct places.
So, I assume that Nuget package manager makes more steps than just call dotnet add package .., but it's unclear what exactly happens, any help will be appreciated.

dododo
  • 3,872
  • 1
  • 14
  • 37
  • also, if anyone can point me out on the "complex" guide to nuget configuration (preferably via `.csproj`), it will be also appreciated – dododo Sep 26 '20 at 23:20
  • Hi, any update about this issue? – Mr Qian Sep 29 '20 at 08:00
  • @PerryQian-MSFT, thanks a lot for your help, I didn't have a chance to deeply check your answer, will do it later today – dododo Sep 29 '20 at 10:32
  • 1
    Thanks for your feedback and we will wait for your any response:) – Mr Qian Sep 30 '20 at 01:58
  • @PerryQian-MSFT, I double-checked this issue, it looks like I was wrong, at least I wasn't able to reproduce exactly the described issue. Most likely my problem was related to the difference in how consumer applications with `csproj`s in `sdk style` and `non-sdk style` are processed. Now, I see that my `non-sdk` project handles .net framework TF correctly (including via PM and Install-Package `package` way), but when I try to use .net framework in `sdk style`, the native library is not copied into the expected place. So, some more investigation is required here. Thanks a lot! – dododo Oct 02 '20 at 22:44
  • `Runtime` folder of the nuget works for new sdk style project. And it is strange why it works for non-sdk projects. You should check on [this document](https://learn.microsoft.com/en-us/nuget/create-packages/supporting-multiple-target-frameworks) and make sure the sructure is right. Besides, please try to use net standard library project as the nuget project. Secondly, you can use [content folder or lib folder](https://learn.microsoft.com/en-us/nuget/reference/nuspec#metadata-attributes) to copies files or reference dlls into your main projects. – Mr Qian Oct 05 '20 at 06:27

1 Answers1

1

Actually, dotnet add package does the same effect as Nuget package manager UI in VS IDE. They simply install a Nuget package into your project and there is no difference. No additional operations will be performed. Like add some xml node in

So I think there is something else wrong in your project.

Please check under tips to troubleshoot your issue:

1) clean nuget caches first or just delete all cache files under C:\Users\xxx(current user)\.nuget\packages.

2) And if the runtimes folder does not exist under your project, I think it is controlled by dependency assets. Like ExcludeAssets=runtime or native. It will prevent the function of runtimes folder. Please see this official document.

So after you finishing installing the nuget package, you should check your csproj file, and make sure that there is no such like

<ExcludeAssets>runtime;native</ExcludeAssets>

under PackageReference node.

If there is any this node, please delete it.

3) delete bin and obj folder. Then rebuild your project to test again. Or if you use dotnet command line, you should additionally add dotnet build command. In my side, I run dotnet build -p:platform=xxx;Configuration=Release.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41