2

I have created a .NET Standard project where I installed the version 4.4.4 of the System.ServiceModel.Http nuget package. This package include also the dll System.ServiceModel.Primitives... I add image:

enter image description here

I have created a nuget package from my project with the command

.\nuget.exe pack MyProjectFile.csproj -Build -ExcludeEmptyDirectories -IncludeReferencedProjects -OutputDirectory  MyOutputDir

Now I must install this package in another solution, in a .NET Framework project. But for some reason when I start the project I obtain this error:

Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.2.0.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

The versione 4.2.0.3 of the dll System.ServiceModel.Primitives is inside the package version 4.4.4

I have edited my .NET Standard project file in this way:

<PackageReference Include="System.ServiceModel.Primitives" Version="4.4.4" />
<PackageReference Include="System.ServiceModel.Http" Version="4.4.4" />

But when I install the package in my .NET Project I still receive that error. No external package has been included in my package... What do I miss?

Thank you

EDIT

I also expected, when I install my nuget package, a window appear and tell me something like "You need to install also the Package A and the Package B. Continue or not?". Nothing appear instead....

Simone
  • 2,304
  • 6
  • 30
  • 79
  • try including `System.ServiceModel.Primitives` manually – Neville Nazerane Dec 06 '18 at 00:47
  • still does not work... always same error – Simone Dec 06 '18 at 05:51
  • I resolved... It seems that .NET Standard Projects ignore `PackageReference` in the project file and they still need `nuspec` file – Simone Dec 06 '18 at 06:53
  • check my solution. I have `PackageReference` included automatically all the time. – Neville Nazerane Dec 06 '18 at 07:48
  • 1
    As Neville answered below, you should use `dotnet pack` to pack SDK projects, rather than `nuget.exe`. It generates the nuspec for you, including dependencies. If you don't use `System.ServiceModel.Primites` directly, I don't recommend adding it as a project reference. Let NuGet get transient dependencies automatically when needed. – zivkan Dec 06 '18 at 20:52

1 Answers1

0

If you are using .net standard projects, you can use the dotnet CLI instead of nuget.exe. I always found it cleaner and a far lesser process. You can use something like this with the dotnet CLI

dotnet pack -c release -o MyOutputDir

Here output folder is optional and config would be "debug" by default. I have used this for several nugets and I never have an issue with nuget references.

Neville Nazerane
  • 6,622
  • 3
  • 46
  • 79
  • clarification: SDK projects. It's possible to use SDK projects to target .NET Framework, and take advantage of multi-targeting and packing. It's not limited to .NET Standard or .NET Core. – zivkan Dec 06 '18 at 20:47