Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget Pkg Dlls Missing from Build Folder in .Net Standard DLL Project. dlls are Not Copy Local? Fix in Visual Studio 2019?

I have Visual Studio 2019 Community Edition

Steps to reproduce:

I load up VS and start a brand new C# .Net Standard Library project. I go to Nuget Pkg Manager and install ANY nuget package. I add a single line to Class1.cs to use a Type from the package.

For instance, if I install WatsonTCP nuget package, I change Class1.cs to look like this:

using System;
using WatsonTcp;

namespace NugetTest
{
    public class Class1
    {
        public Class1()
        {
            WatsonTcpClient client = new WatsonTcpClient("", 0);
        }
    }
}

I hit Rebuild Solution. I check the bin/Debug folder and none of the dlls for the nuget package are there. Same thing with bin/Release for a Release build.

I have poored through as many SO issues as I can. I've read the MSDN documentation on nuget.

I set Build and Run MSBuild settings to Detailed. In the build log, I see something like the following output for every single dll:

Primary reference "WatsonTcp, Version=2.0.7.0, Culture=neutral, PublicKeyToken=null".
Resolved file path is "C:\Users\James\.nuget\packages\watsontcp\2.0.7\lib\netstandard2.0\WatsonTcp.dll".
Reference found at search path location "{HintPathFromItem}".
This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true".

I'm guessing this notice about CopyLocal is the reason nothing is being output in the build folder. But I'm not 100% sure.

SO mostly contains older questions that pertain to the pre-"package reference" era before .Net Core and .Net Standard. As a result, any time I search for issues pertaining to "CopyLocal", I get information on setting the CopyLocal property explicitly on a DLL Reference. I'm not finding anything helpful to fix my issue with automatic determination of CopyLocal by the Package Reference and RAR system.

Can anyone help?

like image 743
JamesHoux Avatar asked Sep 24 '19 17:09

JamesHoux


People also ask

How do I get NuGet package DLL?

Just build the class library by clicking the right click on solution explorer and you will see the NameOfLibrary. dll file in packages folder of your project directory. packages folder isn't displaying as folder in solution explorer. You can see them as References.

How to add Reference to DLL file in asp net?

Add reference to this . dll by right clicking on References > Add Reference > Browse > Select your . dll file and lick OK. Then set it's "Copy Local" property to "True".

What is the difference between NuGet package and DLL?

NET are created, hosted, and consumed, and provides the tools for each of those roles. Put simply, a NuGet package is a single ZIP file with the . nupkg extension that contains compiled code (DLLs), other files related to that code, and a descriptive manifest that includes information like the package's version number.

Where is the DLL located in a NuGet package?

The DLL is found within the Debug folder (or Release if you build that configuration instead). Within a real NuGet package, of course, you implement many useful features with which others can build applications.

Does NuGet package contain consumerlibraryproj3 DLL?

The Nuget package contains only ConsumerLibraryProj3.dll. I verified the above settings for a .NET Standard project and it works. But for .NET Framework type project I'm unable to get it done. Any help will be appreciated.

How to publish a NuGet package in Visual Studio?

Quickstart: Create and publish a NuGet package using Visual Studio (.NET Standard, Windows only) 1 Prerequisites. ... 2 Create a class library project ... 3 Configure package properties. ... 4 Run the pack command. ... 5 Publish the package. ... 6 Adding a readme and other file ...

Why does my Exe project need a DLL file?

If it can run and it indeed needs the dll file, it means that the dll file must be created, otherwise the exe will not run successfully. I can not reproduce your issue on my side, because when I create the dll project and another exe project to use the dll, the exe and dll files are all created.


1 Answers

Open your xx.csproj(In VS, double-click the project name in Solution explorer, or right-click project=>unload=>edit...) and add the CopyLocalLockFileAssemblies property into it, set its value to true and it will copy all your assemblies from nuget packages to output folder during build process.

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <!--Add this line-->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

And if you have too many nuget packages in your project and you only want part of them, try using PrivateAssets="All" to prevent VS from copying the specified one to output folder.

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <!--Add this line to copy everything.-->
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="log4net" Version="2.0.8" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3-beta1" />
    <PackageReference Include="WatsonTcp" Version="2.0.7" PrivateAssets="All"/>
  </ItemGroup>

Eg: Using script above will copy log4net and NewTonSoft.Json but not WatsonTcp to output folder. More details refer to github/dotnet/sdk#2235.

like image 126
LoLance Avatar answered Oct 16 '22 18:10

LoLance