I am trying to use a project as nuget package in other solution.
The project i want to use has 2 references to other projects in the solution he is at.
I am creating the .nupkg file using the cli command dotnet pack
in the path of the project i want to use as a nuget package.
When adding the .nupkg file to the other solution using the command dotnet add package
i get the error in the post title with the name of the 2 references projects.
My Solution was From Visual Studio Main menu:
Tools=>Options=>Nuget Package Manager=>Click On Package Sources
Now add following Package (see the screenshot) and click on Ok.
Build your application and it will be error free.
Using dotnet cli:
As @Lex Li suggests, to use command like dotnet add package xxx
to reference a local package created by yourself, you can choose to set up a local feed and push it to the feed before you do that.(You can also choose to publish the package to nuget.org and other feeds)
A simple way to configure local feed: Nuget.config file controls the behavior of consuming nuget package, you can find the Nuget.config file which works for your current user at: %appdata%\NuGet\NuGet.Config
. You can use the statement like:
<add key="Local Packages" value="C:\path\..." />
to set a folder as your local feed. Then put your xx.nupkg file into it, your issue will go away. Also you can set the feed by UI in VS, see my following description in Install it by VS
. (Apart from that, you could also use Nuget Server.)
Install it by VS:
And since you're trying to consume a package in your local machine with VS installed, you can also consider using VS nuget package manager UI, see this document.
A simple way to do this in VS is to go Tools=>nuget package manager=>package manager settings=>package source
, click the green button to define new package source like C:\xxx\MyLocalPackages
:
Copy your xxx.nupkg file to the folder, and In VS right-click project=>Manage nuget packages=>choose the correct package source and you can easily consume it:
The folder will also work as a local feed for you.
In addition:
I am creating the .nupkg file using the cli command dotnet pack. You can rename the xx.nupkg to xx.zip, and check the content of its lib
folder. Please make sure the assemblies of the referenced two projects locate there.(I met this new issue after I resolve your original issue) If they're not there, you may get a similar issue like this, and here's the workaround from Martin.
Update1:(more details about Martin's workaround) Unload the project in VS to edit the xx.csproj, add this script into it:
<Project>
...
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include = "..\ProjectName\ProjectName.csproj" PrivateAssets="All" />
</ItemGroup>
<Target Name = "IncludeP2PAssets" >
<ItemGroup>
< BuildOutputInPackage Include="$(OutputPath)\ProjectName.dll" />
</ItemGroup>
</Target>
</Project>
Replace the ProjectName with the name of the projects you depend on. Then build it in VS and you can find the xx.nupkg in bin\debug or bin\release. (It should work for .net core or .net standard and I've checked it)
Any update feel free to let me know :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With