Search code examples
visual-studio.net-corenugetnuget-package

Difference in NuGet processing via `dotnet add package ..` vs nugets adding via visual studio UI


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 a .csproj file and a 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 Visual Studio NuGet Package Manager and select "Manage NuGet Packages for Solution", all files are placed into correct places.

So, I assume that NuGet package manager makes more steps than just calling dotnet add package ..., but it's unclear what exactly happens.


Solution

  • Actually, dotnet add package does the same thing as the NuGet Package Manager: they both install a NuGet package into your project. No additional operations will be performed.

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

    Please check under tips to troubleshoot your issue:

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

    2. 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.

      After you finishing installing the NuGet package, you should check your .csproj file, and make sure that there is nothing like

      <ExcludeAssets>runtime;native</ExcludeAssets>
      

      under the PackageReference node.

      If there is any such content under this node, please delete it.

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