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.
-
You need to set up a local NuGet feed, https://learn.microsoft.com/en-us/nuget/hosting-packages/local-feeds, then add the generated packages there. Only from then on you can add references from that feed and achieve your goal. Raw packages without a feed cannot work. – Lex Li Sep 20 '19 at 00:30
-
Please let me know if it helps, and if your original issue is resolved by my answer, you could consider marking it as answer. Just a reminder :) – LoLance Sep 23 '19 at 09:30
2 Answers
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.

- 7,252
- 10
- 25
- 39

- 331
- 3
- 4
-
-
IDK why this was an issue for me, never has been before. I was aware of this screen, just didn't know that I needed to add nuget.org of all sources! Thanks for making it obvious. – Don Rolling Jun 21 '22 at 16:54
-
Thanks It worked for me? One question is i never faced this issue before with fresh installation of VS 2019 why this time ? – Sneha Aug 22 '22 at 11:04
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 :)
-
This is the second issue you mentioned, I do not have the 2 referenced assemblies at the lib folder of the nuget. The workaround of martin did not helped, Also it did not auto-complete the `
` tag as if its not a known tag. The same is true for ` – ATT Sep 22 '19 at 06:41` tag & ` ` from the workaround. -
**UPDATE:** After using dotnet pack anyways, It did tried to pack like the tags are ok, but it says `error NU5026: The file '${OutputPath}\nameOfTheDll.dll' to be packed was not found on disk. [OutputDir\project.csproj]`. The referenced dlls exits at the `bin\Release\netcoreapp2.2` folder of the app – ATT Sep 22 '19 at 06:56
-
@ATT Please see my update, it's recommended that you build it in VS. You can add the script into your project file, then right-click the project C (nuget package)=>build, since it depends on project A and B, it will build A and B first. then build C. And during the build of project C, it will copy A.dll and B.dll to output path. So you need to build them before pack them. For this, you can right-click project C=>Pack to easily do this. And for the reason why you get dotnet pack, please check what configuration do you choose, make sure you've built the project in corresponding configuration. – LoLance Sep 23 '19 at 09:29