NuGet package dependent DLLs not copied to output folder

I am having a problem with the custom Nuget package I created. Let me call it MyCompany.Library.nupkg. It is hosted on the corporate tutor of Artifactory Nuget. This package is dependent on Newtonsoft.Json. For some reason, the dependent DLL is not copied to the output folder of my project if I refer to a project that uses this Nuget package. It is strange that when I use another package (for example, Moq, instead of my own), the dependent DLLs are copied.

I created a test solution to reproduce the problem:

ReferenceTest Solution:

  • Project: SomeLib.dll; Recommendations:
    • MyCompany.Library Nupkg (depends on Newtonsoft.Json, so added too)
    • Moq Nupkg (Depends on Castle.Core, added too)
  • Project: MyWinFormsApp.exe; Project link:
    • SomeLib.csproj

When I look at the output folder of SomeLib, I see:

  • Somelib.dll
  • Moq.dll
  • Castle.Core.dll
  • MyCompany.Library.dll
  • Newtonsoft.Json.dll

It looks good.

But when I look at the output folder of MyWinFormsApp, Newtonsoft.Json.dll is missing, and when the application starts, it throws exceptions that are not found in the Newtonsoft.Json DLL. However, Castle.Core.dll IS in the output folder MyWinFormsApp.

I compared nuspecs Moq and MyCompany.Library, and I can not find the significant difference.

I could change the whole project that my SomeLib uses to link to Newtonsoft.Json, but these are many projects, and I do not want to bother other developers with this. They do not need to know that SomeLib uses this assembly.

The links in SomeLib.csproj are as follows:

  <ItemGroup>
    <Reference Include="MyCompany.Library, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>..\packages\MyCompany.Library.1.0.0\lib\net461\MyCompany.Library.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
      <HintPath>..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Moq, Version=4.5.28.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
      <HintPath>..\packages\Moq.4.5.28\lib\net45\Moq.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=8.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
      <HintPath>..\packages\Newtonsoft.Json.8.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>

My Nuspec looks like this:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyCompany.Library</id>
    <version>0.0.0</version>
    <description>MyCompany Core library</description>
    <authors>MyCompany</authors>
    <references>
      <reference file="MyCompany.Library.dll" />
    </references>
    <dependencies>
      <dependency id="Newtonsoft.Json" version="[8.0,9.0.1]" />
    </dependencies>    
  </metadata>
  <files>
    <file src="MyCompany.Library\bin\Release\MyCompany.Library.dll" target="lib\net461"/>
    <file src="MyCompany.Library\bin\Release\MyCompany.Library.pdb" target="lib\net461"/>
    <file src="MyCompany.Library\bin\Release\MyCompany.Library.xml" target="lib\net461"/>
  </files>
</package>

Visual Studio 2015 Professional.

:

  • Visual Studio dll?
  • Moq? ?

.

Quido

NUSPEC Moq ( ), . Moq Nuspec :

<dependencies>
  <group targetFramework=".NETFramework4.5">
    <dependency id="Castle.Core" version="3.3.3" />
  </group>
</dependencies>

:

<dependencies> 
  <dependency id="Newtonsoft.Json" version="[8.0,9.0.1]" /> 
</dependencies>     

, targetFramework, VisualStudio !

NuSpec - , , . , ( targetFramework targetFramework).

: , , ...

+6
2

"Newtonsoft.json" . , " " "".

0

1. Visual Studio dll?

, MSBuild ( DLL) , SomeLib . .

2. Moq? ?

, Moq MyWinFormsApp. , Moq MyWinFormsApp, MyWinFormsApp, , SomeLib.

, .

0

Source: https://habr.com/ru/post/1016354/


All Articles