I have two class libraries in a single solution (.NET Core). One of them ( cl1
) is a main library and it depends on another library ( cl2
). I have added a .nuspec
file with the required metadata only (no dependencies, no files) for the cl1
project in the project folder (same location of .csproj
file) and I have set GeneratePackageOnBuild
propery to true
. Whenever I am building the class library ( cl1
), the .nupkg
is created automatically in the debug/release folder.
When I check the generated .nupkg
file, I am see two strange things:
.nuspec
file is different than what I have added in the project foldercl2
is mentioned as a dependency in the newely generated .nuspec
file, but the DLL for cl2
is not included in the lib
folder of the .nupkg
. So, whenever I consume this package in another solution, I am getting the error No packages exist with this id in source(s)
for the cl2
.I have surfed in internet, but was not able to find a proper solution for the above error.
And I have added a.nuspec file [...] in the project folder(same location of.csproj file)
You have to specify the path to your own NuSpec file in the .csproj
using the NuspecFile
tag, otherwise it will be ignored and the package will be created with the metadata from the .csproj
file instead, see reference . You need to use either a relative or an absolute path to the file, for example:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<NuspecFile>cl1.nuspec</NuspecFile>
</PropertyGroup>
</Project>
- The generated.nuspec file is different than what I have added in the project folder
As already stated, your NuSpec file is probably not included. However, even if it is, there can be differences, because some information , eg source file locations are unnecessary and the target locations are in most cases given by the internal package file structure itself, so it is not there because it is redundant.
- cl2 is mentioned as a dependency in the newely generated.nuspec file, but the dll for the cl2 is not included in the lib folder of the.nupkg. So, whenever I consume this nupkg in other solution, I am getting error " No packages exist with this id in source(s)" for the cl2.
Dependencies are meant for packages . So when NuGet restores the package it searches for other packages that this package depends on, here cl2
, but there is none, hence the error. When packing a project, referenced projects are not included in the package. That is an open issue and there are workarounds that you can try.
The most reliable, but inconvenient solutions are to avoid the issue at all.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.