问题
I have a PCL library I want to distribute as NuGet package.
Screenshot of the PCL application library properties page:
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:
Clone both repos from:
- NuGet package
- Console application + PCL library
Build the NugetPackage project +
nuget spec
+nuget pack
- Create a local nuget package repository pointing to the project folder.
- Open the NugetConsole solution and try installing the package in both projects.
Some references I used:
- https://docs.microsoft.com/en-us/nuget/schema/target-frameworks
- https://docs.microsoft.com/en-us/nuget/schema/nuspec
- https://portablelibraryprofiles.stephencleary.com/
- http://blog.stephencleary.com/2012/05/framework-profiles-in-net.html
回答1:
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:
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
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.
来源:https://stackoverflow.com/questions/48319497/nuget-package-from-pcl