I want to list down all the nuget packages along with its dependencies recursively.
Project is in VS2017 and .NET Core.
I tried with Get-Package -ProjectName "Your.Project.Name" it displays all the nuget packages in project. I want all the dependencies also printed.
You can use the dotnet cli: dotnet list package --include-transitive. The dotnet-outdated global tool probably has similar functionality.
Related
Creating a dotnet tool is like creating a nuget package. We create it by dotnet pack command and publish him to nuget feed.
But we can't use it as nuget package in our C# project, although it is a nuget!
Can I create a one Console Application project and publish it as dotnet tool, and then use it as nuget package in a C# project?
Publish your tool as NuGet package, add the dir you published to to the NuGet soruces (VS:Tool>Options>NuGet>big-green-plus-button).
Open the NuGet package Manager in the Project you want the use the NuGet package and select your source, wait for NuGet to load, and then install the NuGet tool you published
I have a .NET project with the following in its .csproj
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
When I run dotnet restore project-file.csproj I get the following:
Nothing to do. None of the projects specified contain packages to restore.
Why is this? I thought the dotnet cli could work with non Core projects too?
I have nuget packages that are referenced, so I expect the cli to go and download the nuget packages.
dotnet cli works properly with .NET Framework only if the project was created from dotnet new command. If you create project from Visual Studio the structure of .csroj files will be different and you usually cannot run cli commands towards them
Visual Studio only allows you to run nuget commands from nuget console (package manager console) within Visual Studio itself.
If you want to do nuget restore from command line:
Download nuget executable from https://www.nuget.org/downloads
(it is not a installer/package, but actual executable!)
Save it to a folder of your choice and add it to the PATH.
Then, as suggested above: nuget restore solutionname.sln (but this time you don't have to run Visual Studio!)
I am having c# .net core project. Project name is Master and it has dependencies of external NuGet package as "SpecFlow.CustomPlugin". Master project has Two classes as Shape.cs and Factory.cs.
When I generate the NuGet package of Master project so that the implementation of Shape.cs and Factory.cs class can be useful as library into other projects. After generating the NuGet package of Master project I only see the "SpecFlow.CustomPlugin" content with it's own dependent dll files but I am not able to see dll of Master project in newly generated NuGet package.
Newly generated NuGet package is included in another project let's say Consumer. Consumer want to use the Shape.cs method and Factory.cs method but it's not accessible.
Master project Dependencies looks like:
First, make sure that Shape and Factory are public. If you don't specify their visibility, they're private by default, which means that they can not be used directly by other projects, either as package reference or project references.
When you pack master into a NuGet package, the default file it will create is bin\Debug\master.1.0.0.nupkg. Assuming master is targetting .NET Standard 2.0, master's dll is saved as lib\netstandard20\master.dll in the nupkg. You need add/push this nupkg to a nuget feed (can be a directory on your computer or network, nuget.org or you can host your own feed). Your comsumer project will need a nuget.config that adds the correct NuGet feed as a source, then you add a package reference to the master package. After you restore (which Visual Studio does automatically if you added the package with the UI), then you can use any of master's public classes.
Here's commands you can run on the command line to set up two projects, one is a package, the other will consume it. If you're using .NET Core in Visual Studio, it must have already downloaded the .NET Core SDK, which puts the dotnet cli on your path. You'll also need to download nuget.exe from https://www.nuget.org/downloads/.
dotnet new nugetconfig
nuget source -configfile nuget.config add -name local -source feed
# create an isolated nuget environment, because I don't like to populate
# my global packages folder with test packages
nuget config -configfile nuget.config -set globalPackagesFolder=gpf
# create a library, pack it, and add the nupkg to our local feed
dotnet new classlib -n MyLib
dotnet pack MyLib\MyLib.csproj -o nupkgs\
nuget add MyLib\bin\Debug\MyLib.1.0.0.nupkg -s local
# create console app and reference MyLib
dotnet new console -n MyApp
dotnet add MyApp\MyApp.csproj package MyLib --version 1.0.0
#if you want to open these projects in Visual Studio
dotnet new sln -n sample
dotnet sln add MyLib\MyLib.csproj
dotnet sln add MyApp\MyApp.csproj
start sample.sln
Normally you wouldn't use a NuGet package to use one project from another project in the same solution. Just make them project references, and when you pack a project into a NuGet package, the project reference becomes a NuGet dependency. I only did it this way to demonstrate how to easily consume a package that you created yourself.
All .NET framework projects that use Nuget have a packages.config per project. When I run something like:
nuget update MySolution.sln -Id PackageName -Version 1.2.3
It will update all projects in my solution that use this package to the specified version (1.2.3 in this case)
However, I'm finding that this does NOT work for UWP projects. UWP does not use packages.config and instead put the package references directly into the csproj file. As a result, this is literally what nuget update says when I run it:
Found 2 projects with a packages.config file. (A.csproj, B.csproj)
where A and B are my .NET Framework projects that still have a packages.config file. But this list doesn't include my new UWP projects.
Is there another command for nuget update that will work with UWP projects?
How do I update UWP projects' nuget packages via the CLI?
This is a known issue for the packagereference. At the moment, NuGet CLI does not support automatic package updates to the the new .NET Core .csproj format, you can refer to the below GitHub issue for details:
support for updating references into csproj from commandline(s)
Besides, as test, the workaround using following command line does not work with UWP project
dotnet add package <PackageName> --version <version>
Indeed, currently it is very inconvenient to manage packages outside of Visual Studio for UWP with packagereference.
Hope this helps.
Do Nuget packages only work on a Solution level?
Or is it possible to create nuget packages for only Specific Projects in a solution? I have a single project which I want to nugetize, and would like to ignore the rest.
use dotnet pack <PROJECT> to create a nuget package of a .Net Core project