1

I have a netstandard2.0 nugget package that has some dependencies:

<!-- Nugget Package dependencies -->
<ItemGroup>
    <PackageReference Include="JetBrains.Annotations" Version="2020.1.0" PrivateAssets="All" />
    <PackageReference Include="Serilog" Version="2.9.0" PrivateAssets="All" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" PrivateAssets="All" />
    <PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.13" PrivateAssets="All" />
    <PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" PrivateAssets="All" />
    <PackageReference Include="Serilog.Sinks.Async" Version="1.4.0" PrivateAssets="All" />
    <PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" PrivateAssets="All" />
    <PackageReference Include="Serilog.Sinks.File" Version="4.1.0" PrivateAssets="All" />
</ItemGroup>

Every time I install this package on a another project, it adds it's dependencies, like:

<ItemGroup>
    <Reference Include="PackageXPTO, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
        <HintPath>..\packages\PackageXPTO.1.1.0\lib\netstandard2.0\PackageXPTO.dll</HintPath>
    </Reference>
    <Reference Include="JetBrains.Annotations, Version=2020.1.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
        <HintPath>..\packages\PackageXPTO.1.1.0\lib\netstandard2.0\JetBrains.Annotations.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
        <HintPath>..\packages\PackageXPTO.1.1.0\lib\netstandard2.0\Newtonsoft.Json.dll</HintPath>
    </Reference>
    <Reference Include="Newtonsoft.Json.Schema, Version=3.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
        <HintPath>..\packages\PackageXPTO.1.1.0\lib\netstandard2.0\Newtonsoft.Json.Schema.dll</HintPath>
    </Reference>
    <Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
        <HintPath>..\packages\PackageXPTO.1.1.0\lib\netstandard2.0\Serilog.dll</HintPath>
    </Reference>
    <Reference Include="Serilog.Enrichers.Thread, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
        <HintPath>..\packages\PackageXPTO.1.1.0\lib\netstandard2.0\Serilog.Enrichers.Thread.dll</HintPath>
    </Reference>
    (...)

This is messing with a project that I have that already depends on Newtonsoft.Json: the old dependency will now be related to the nugget and not a direct dependency: so, on the future, if this nugget no longer deppends on the Newtonsoft.Json, the dependency will be removed, but the project actually needs it.

Package configurations:

<PropertyGroup>
    <AssemblyName>PackageXPTO</AssemblyName>
    <RootNamespace>PackageXPTO</RootNamespace>
    <TargetFramework>netstandard2.0</TargetFramework>
    <Version>1.1.0</Version>
    <SignAssembly>true</SignAssembly>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <AppxAutoIncrementPackageRevision>true</AppxAutoIncrementPackageRevision>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
    <LangVersion>7.2</LangVersion>
    <PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
    <TreatSpecificWarningsAsErrors />
    <PublishRepositoryUrl>true</PublishRepositoryUrl>
    <EmbedUntrackedSources>true</EmbedUntrackedSources>
    <IncludeSymbols>true</IncludeSymbols>
    <SymbolPackageFormat>snupkg</SymbolPackageFormat>
    <TargetsForTfmSpecificBuildOutput>IncludeDependentDlls</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>

Already tried to merge built .dll files, but didn't work

 <!-- Auto bundler - used to apply package reference dll files -->
<!-- Include all .dll files under build directory, excluding the self one (to avoid errors) -->
<Target Name="IncludeDependentDlls" DependsOnTargets="ResolveReferences">
    <ItemGroup>
        <BuildOutputInPackage Include="$(OutputPath)\*.dll" Exclude="$(OutputPath)\$(AssemblyName).dll" />
    </ItemGroup>
</Target>
fiskolin
  • 1,421
  • 2
  • 17
  • 36
  • Have you tried to [Update NuGet Packages](https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages) then to use [Migrate from packages.config to PackageReference](https://learn.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference)? In my case these 2 steps were very helpful in multi-developer environment! – Maciej Los Apr 28 '20 at 17:40
  • @MaciejLos The issue is related to NuGet package creation, not (directly) its installation in a project. Or did I miss something? – fiskolin Apr 29 '20 at 08:39
  • Sorry, i misunderstood the question. – Maciej Los Apr 30 '20 at 05:31
  • Which Newtonsoft.Json version do you use in your target project that uses the nuget package? –  May 02 '20 at 13:40
  • @Stefan `v12.0.2`, why? – fiskolin May 02 '20 at 14:13
  • Did you get a FileNotFoundException when you starting the app? Because the versions are different in the nuget and target project. Or creates your target project `BindingRedirects`? –  May 02 '20 at 14:18
  • @Stefan when I install the nugget on target project, the project has no more a direct dependency to Newtonsoft.Json but now depends on the nugget's Newtonsoft.Json dependency. No error, I don't want to mess with the project' dependencies – fiskolin May 02 '20 at 14:48
  • You can use assembly binding redirections to explicitly point to the version of the top-level Newtonsoft.Json dependency in case there is a version mismatch. If the package you're talking about removes Newtonsoft.Json as its dependency in the future, then the configuration file of your project will be updated by the visual studio making the top-level Newtonsoft.Json the only one. – Pavisa May 02 '20 at 16:29

0 Answers0