0

I'm working on a class library that I've multi-targetted to both net461 and netstandard2.0

One of the dependencies of this class library is Microsoft.ApplicationInsights

When it was targeting just net461, I could add a reference to Microsoft.ApplicationInsights (v2.4.0) via package manager console, or nuget ui, and it would add itself as a dependency.

Once I've multi-targetted the csproj:

 <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
  </PropertyGroup>

</Project>

... if I try to add a reference, it asks me to accept license agreements for many, many dependencies. Of course, I duly did so.

My issue comes when I package this class library as a nuget package.

Even if my consuming application targets net461, when I install this package, I am prompted to install all the netstandard dependencies - even if my consuming application doesn't target netstandard.

Is there a way to stop my net461 targetted package requiring all the dependencies for netstandard?

Alex
  • 37,502
  • 51
  • 204
  • 332
  • Hey Alex, I just tried this locally cause it wasn't what I was expecting, and I get a different result. When I create a `net451` console app, and add a new mutli-targeted package (as you've defined above), I only get `Microsoft.ApplicationInsights` and `System.Diagnostics.DiagnosticSource` as expected, and no `NETStandard.Library`. Am I missing a step? – Stuart Jun 25 '18 at 16:52
  • I would recommend looking at the contents of `obj\project.assets.json` to see what is pulling in those dependencies, cause what what you've described it will not be the app insights package. – Stuart Jun 25 '18 at 19:29
  • 1
    So, this was ultimately caused by an up-stream dependency of the package not being upgraded! I've voted to close this question. – Alex Jun 26 '18 at 16:10

1 Answers1

2

Have you tried using conditions in the project file to make some dependencies target framework specific? I've had similar sounding problems, though not with creating nuget packages, and this helped.

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
    <Reference Include="DependencyA" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
    <PackageReference Include="DependencyB" Version="1.0.0" />
  </ItemGroup>

</Project>

Another idea would be to look at existing open source projects out there and see how they're solving it. Though finding one using Microsoft.ApplicationInsights may be trickier.

Tom Robinson
  • 8,348
  • 9
  • 58
  • 102
  • Problem is, `DependencyA` and `DependencyB` are exactly the same - including the same version – Alex Jun 26 '18 at 09:56