<<

nuget download specific version How to install the Nuget Package using PowerShell? Nuget is the package management tool for the .NET and it is similar to PowerShellGet, MSI packages which support several commands and packages to work with PowerShell. NuGet supports Install−Package, Update−Package, Find-Package, and Get−Package command and if Nuget package is not installed in your system, you may not find a package or install any package. For more reference about Nuget, check the websites below. To install NuGet, we need to use the Install−PackageProvider command. Use the below command to install the Nuget package. On some machines, you will get the error message regarding downloading the package from the internet. If you have the proxy set in your environment, you can configure the proxy, or if there is no issue with proxy, and if your System TLS version is 1.1 then it should be first changed to 1.2 using the below command. Once the above command runs successfully, use the first command to install the Nuget package. When the NuGet package is installed, use the below command to check if the Nuget provider exists on the system or not. Manage packages using the .exe CLI. The CLI tool allows you to easily update and restore NuGet packages in projects and solutions. This tool provides all NuGet capabilities on Windows, and also provides most features on Mac and when running under . The nuget.exe CLI is for your .NET Framework project and non-SDK-style projects (for example, a non-SDK style project that targets .NET Standard libraries). If you are using a non-SDK-style project that has been migrated to PackageReference , use the dotnet CLI instead. The nuget.exe CLI requires a packages.config file for package references. In most scenarios, we recommend migrating non-SDK-style projects that use packages.config to PackageReference, and then you can use the dotnet CLI instead of the nuget.exe CLI. Migration is not currently available for C++ and ASP.NET projects. This article shows you basic usage for a few of the most common nuget.exe CLI commands. For most of these commands, the CLI tool looks for a project file in the current directory, unless a project file is specified in the command. For a complete list of commands and the arguments you may use, see the nuget.exe CLI reference. Prerequisites. Install the nuget.exe CLI by downloading it from nuget.org, saving that .exe file to a suitable folder, and adding that folder to your PATH environment variable. Install a package. The install command downloads and installs a package into a project, defaulting to the current folder, using specified package sources. Install new packages into the packages folder in your project root directory. The install command does not modify a project file or packages.config ; in this way it's similar to restore in that it only adds packages to disk but does not change a project's dependencies. To add a dependency, either add a package through the UI or Console in Visual Studio, or modify packages.config and then run either install or restore . Open a command line and switch to the directory that contains your project file. Use the following command to install a NuGet package to the packages folder. To install the Newtonsoft.json package to the packages folder, use the following command: Alternatively, you can use the following command to install a NuGet package using an existing packages.config file to the packages folder. This does not add the package to your project dependencies, but installs it locally. Install a specific version of a package. If the version is not specified when you use the install command, NuGet installs the latest version of the package. You can also install a specific version of a Nuget package: For example, to add version 12.0.1 of the Newtonsoft.json package, use this command: For more information on the limitations and behavior of install , see Install a package. Remove a package. To delete one or more packages, delete the packages you want to remove from the packages folder. If you want to reinstall packages, use the restore or install command. List packages. You can display a list of packages from a given source using the list command. Use the -Source option to restrict the search. For example, list packages in the packages folder. If you use a search term, the search includes names of packages, tags, and package descriptions. Update an individual package. NuGet installs the latest version of the package when you use the install command unless you specify the package version. Update all packages. Use the update command to update all packages. Updates all packages in a project (using packages.config ) to their latest available versions. It is recommended to run restore before running update . Restore packages. Use the restore command, which downloads and installs any packages missing from the packages folder. For projects migrated to PackageReference, use -t:restore to restore packages instead. restore only adds packages to disk but does not change a project's dependencies. To restore project dependencies, modify packages.config , then use the restore command. As with the other nuget.exe CLI commands, first open a command line and switch to the directory that contains your project file. To restore a package using restore : Get the CLI version. Use this command: The first line in the help output shows the version. To avoid scrolling up, use nuget help | more instead. Quickstart: Install and use a package in Visual Studio (Windows only) NuGet packages contain reusable code that other developers available to you for use in your projects. See What is NuGet? for background. Packages are installed into a Visual Studio project using the NuGet Package Manager, the Package Manager Console, or the dotnet CLI. This article demonstrates the process using the popular Newtonsoft.Json package and a Windows Presentation Foundation (WPF) project. The same process applies to any other .NET or .NET Core project. Once installed, refer to the package in code with using where is specific to the package you're using. Once the reference is made, you can call the package through its API. Start with nuget.org : Browsing nuget.org is how .NET developers typically find components they can reuse in their own applications. You can search nuget.org directly or find and install packages within Visual Studio as shown in this article. For general information, see Find and evaluate NuGet packages. Prerequisites. Visual Studio 2019 with the .NET Desktop Development workload. You can install the 2019 Community edition for free from visualstudio.com or use the Professional or Enterprise editions. Create a project. NuGet packages can be installed into any .NET project, provided that the package supports the same target framework as the project. For this walkthrough, use a simple WPF app. Create a project in Visual Studio using File > New Project , typing .NET in the search box, and then selecting the WPF App (.NET Framework) . Click Next . Accept the default values for Framework when prompted. Visual Studio creates the project, which opens in Solution Explorer. Add the Newtonsoft.Json NuGet package. To install the package, you can use either the NuGet Package Manager or the Package Manager Console. When you install a package, NuGet records the dependency in either your project file or a packages.config file (depending on the project format). For more information, see Package consumption overview and workflow. NuGet Package Manager. In Solution Explorer, right-click References and choose Manage NuGet Packages . Choose "nuget.org" as the Package source , select the Browse tab, search for Newtonsoft.Json , select that package in the list, and select Install : If you want more information on the NuGet Package Manager, see Install and manage packages using Visual Studio. Accept any license prompts. (Visual Studio 2017 only) If prompted to select a package management format, select PackageReference in project file : If prompted to review changes, select OK . Package Manager Console. Select the Tools > NuGet Package Manager > Package Manager Console menu command. Once the console opens, check that the Default project drop-down list shows the project into which you want to install the package. If you have a single project in the solution, it is already selected. Enter the command Install-Package Newtonsoft.Json (see Install-Package). The console window shows output for the command. Errors typically indicate that the package isn't compatible with the project's target framework. If you want more information on the Package Manager Console, see Install and manage packages using Package Manager Console. Use the Newtonsoft.Json API in the app. With the Newtonsoft.Json package in the project, you can call its JsonConvert.SerializeObject method to convert an object to a human-readable string. Open MainWindow.xaml and replace the existing Grid element with the following: Open the MainWindow.xaml.cs file (located in Solution Explorer under the MainWindow.xaml node), and insert the following code inside the MainWindow class: Even though you added the Newtonsoft.Json package to the project, red squiggles appears under JsonConvert because you need a using statement at the top of the code file: Build and run the app by pressing F5 or selecting Debug > Start Debugging : Select on the button to see the contents of the TextBlock replaced with some JSON text: CheezyCode. NuGet is commonly used as Visual Studio Extension and helps various developers across the globe to create and consume packages. Its easy, convenient and hassle free. The scope of this article is to make you aware about NuGet and how one can consume a package. We will mainly learn about Installing/Consuming a package and then Uninstalling/Removing the package. Lets talk more about it. What Is NuGet? NuGet is the package manager for the Microsoft development platform including .NET. The NuGet client tools provide the ability to produce and consume packages to the developers. The NuGet Gallery is the central package repository that is used by all package authors and consumers. Install and manage packages using the dotnet CLI. The CLI tool allows you to easily install, uninstall, and update NuGet packages in projects and solutions. It runs on Windows, Mac OS X, and Linux. The dotnet CLI is for use in your .NET Core and .NET Standard project (SDK-style project types), and for any other SDK-style projects (for example, an SDK-style project that targets .NET Framework). For more information, see SDK attribute. This article shows you basic usage for a few of the most common dotnet CLI commands. For most of these commands, the CLI tool looks for a project file in the current directory, unless a project file is specified in the command (the project file is an optional switch). For a complete list of commands and the arguments you may use, see the .NET Core command-line interface (CLI) tools. Prerequisites. The .NET Core SDK, which provides the dotnet command-line tool. Starting in Visual Studio 2017, the dotnet CLI is automatically installed with any .NET Core related workloads. Install a package. dotnet add package adds a package reference to the project file, then runs dotnet restore to install the package. Open a command line and switch to the directory that contains your project file. Use the following command to install a NuGet package: For example, to install the Newtonsoft.Json package, use the following command. After the command completes, look at the project file to make sure the package was installed. You can open the .csproj file to see the added reference: Install a specific version of a package. If the version is not specified, NuGet installs the latest version of the package. You can also use the dotnet add package command to install a specific version of a NuGet package: For example, to add version 12.0.1 of the Newtonsoft.Json package, use this command: List package references. You can list the package references for your project using the dotnet list package command. Remove a package. Use the dotnet remove package command to remove a package reference from the project file. For example, to remove the Newtonsoft.Json package, use the following command. Update a package. NuGet installs the latest version of the package when you use the dotnet add package command unless you specify the package version ( -v switch). Restore packages. Use the dotnet restore command, which restores packages listed in the project file (see PackageReference). With .NET Core 2.0 and later, restore is done automatically with dotnet build and dotnet run . As of NuGet 4.0, this runs the same code as nuget restore . As with the other dotnet CLI commands, first open a command line and switch to the directory that contains your project file.