0

I have a C# Class Library (CL) that I need to package into a nuget package. This project targets .Net Standard 2.0 and has a .csproj file that looks like this:

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

  <PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <Version>1.0.13</Version>
    <PackageTags>custom task</PackageTags>
    <PackageIconUrl></PackageIconUrl>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
    <DocumentationFile>C:\xxx\xxx\xxx.xml</xxx>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
    <DocumentationFile>xxx.xml</DocumentationFile>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="TaskMetadata.json">
      <PackagePath>TaskMetadata.json</PackagePath>
      <Pack>True</Pack>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.2.0" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.1" />
  </ItemGroup>

</Project>

Now the challenge is creating the package and these are the methods I have tried.

  1. In VS, right click the project and pick publish. This creates a nuget package that does not include any of the third party dependencies such as Newtonsoft.json, SqlClient etc.

  2. nuget pack xxx.csproj -IncludeReferencedProjects This results in

    Error NU5012: Unable to find 'bin\Debug\xxx\bin\Debug\'. Make sure the project has been built.

  3. nuget pack xxx.csproj -c Release This results in

    File 'C:\projects\xxx\xxx\Release' does not exist.

4 Unpacking the nuget package from try 1 and extracting the xxx.nuspec file and then running nuget pack xxx.nuspec but this seem to package eveything in the entire folder.

How can I package my library in a nuget version containing only release compiled code and third party dependencies? I would prefer to not having to sync both a .csproj file and .nuspec file all the time to make this work.

Essej
  • 892
  • 6
  • 18
  • 33
  • Check the release and debug folders and see if they contain the same dlls. It seems the debug folder has all the dlls but the release may not. – jdweng Jun 08 '20 at 11:41
  • My debug and release folder has the same files: xxx.deps.json,xxx.dll,xxx.pdb,xxx.xml – Essej Jun 08 '20 at 11:46
  • With same dates? – jdweng Jun 08 '20 at 11:54
  • doesn't the dependencies get auto installed from nuget when your package is installed ? I think you don't need to copy those in to your package check this : https://stackoverflow.com/questions/28229892/nuget-package-dependencies – Vilsad P P Jun 08 '20 at 11:54
  • @jdweng yep But I'm not going to use the package in vs, its on a platform that runs its as custom tasks. I only need the compiled third party dependencies. – Essej Jun 08 '20 at 12:13
  • I know this is old but did you every find an answer? – AliK Nov 26 '21 at 14:58

0 Answers0