ʃʈɑɲ
ʃʈɑɲ

Reputation: 2694

NuGet package from PCL

I have a PCL library I want to distribute as NuGet package.

Screenshot of the PCL application library properties page: screenshot.001

csproj file:

<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Steps to reproduce my problem:

  1. Clone both repos from:

  2. Build the NugetPackage project + nuget spec + nuget pack

  3. Create a local nuget package repository pointing to the project folder.
  4. Open the NugetConsole solution and try installing the package in both projects.

Some references I used:

Upvotes: 0

Views: 840

Answers (1)

Leo Liu
Leo Liu

Reputation: 76996

How can I make a nuget package from a PCL library and use it in a PCL library?

I have downloaded your nuget package and test projects, I can created the nuget package and installed it to the both projects. Following are my detailed steps:

1. Create nuget package:

Download the nuget project, then build the project+nuget spec+nuget pack:

Here is the .nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>My.Package</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2018</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
    <files>
       <file src="bin\**" target="lib\portable-net45+wp8\" />
    </files>
</package>

Note: Since you are planning use this package into PCL library, so the target should be .net45 + Profile49, according to the document Portable Class Library (PCL) profiles, nuget target should be portable-net45+wp8:

enter image description here

enter image description here

2. Install that package to both projects:

Download those two test projects from GitHub, and open it with Visual Studio 2017, then copy the created package to the local nuget feed:

Open Package manager Console, install the package with following command:

install-package My.Package -source D:\LocalServer

enter image description here

So the nuget package is correct install in both projects.

Note: I have seen following code in your project file of console application:

  <ItemGroup>
    <PackageReference Include="My.Package">
      <Version>1.0.0</Version>
    </PackageReference>
  </ItemGroup>

Please remove it, this is not a correct way to add nuget package.

Upvotes: 1

Related Questions