Error creating NuGet package for Portable Class Li

2019-04-08 09:34发布

问题:

I'm new to Nuget and I'm trying to create a NuGet package for a Portable Class Library project that has a package dependency on another portable class library I've created.

I'm running into an issue where I'm receiving an error when calling nuget pack for the project file TestComponent2.csproj (I created this from the Portable for Universal Apps template in VS 2013). This library has a dependency on a nuget package created from another PCL called TestComponent1.

The package created never seems to contain this dependency (the console output even says "Dependencies: None"). However it is in the packages.config file for the TestComponent2 project the dependency is definitely listed:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="TestComponent1" version="1.0" targetFramework="portable-win81+wpa81" />
</packages>

So in my situation I'm calling the following from the command line for a project called TestComponent2, from the folder containing the TestComponent2.csproj and packages.config, with verbosity turned on:

> nuget pack TestComponent2.csproj -Verbosity Detailed

WARNING: Unable to extract metadata from 'TestComponent2.dll'. WARNING: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ---> System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, B oolean suppressSecurityChecks)

...

Add file 'mypath\TestComponent2.dll' to package as 'lib\portable-win81+wpa81\TestComponent2.dll'

Found packages.config. Using packages listed as dependencies
WARNING: Description was not specified. Using 'Description'.
WARNING: Author was not specified. Using 'myname'.

Id: TestComponent2
Version: 1.0
Authors: myname
Description: Description
Dependencies: None

Added file 'lib\portable-win81+wpa81\TestComponent2.dll'.

Successfully created package 'mypath\TestComponent2.1.0.nupkg'.

If I call nuget spec first I also get the following error: WARNING: Unable to extract metadata from 'TestComponent2.dll'. Using 'TestComponent2.nuspec' for metadata. The replacement token 'title' has no value.

Is there an issue with nuget creating packages for the new universal PCL? Or perhaps I have some configuration wrong? I'm using Nuget 2.8.

回答1:

It looks like there is a bug in NuGet 2.8 causing it to fail to read the metadata from a PCL assembly.

I was going to suggest you try an older version of NuGet but unfortunately I think you need 2.8.1 since you are using the Windows Phone Application target (wpa) which is only supported in 2.8.1 or above.

A workaround would be to use nuget pack YourNuSpecFile.nuspec instead of using the project file. However you will need to put more information in the .nuspec to get this to work.



回答2:

This issue is patched in 3.0.0

until 3.0.0 is released, I have created this repository that contains a patched executable that I have been using for the past few months. The repository also contains a sample project to better visualize the issue and how it can occur under simple, yet unexpected circumstances.

A direct link to the executable is here: https://bitbucket.org/patsissons/nugetpclissue/src/HEAD/.nuget-patched/NuGet.exe?at=master