How to Use nuget

1. Downloading packages to a build server
Motivation:

You have a .NET solution that uses NuGet package manager.

You have many files in the packages folder and want them to be downloaded to your build server.

Solution:
  • Download Windows x86 Commandline.
  • Copy nuget.exe to an folder and add the folder path to Windows PATH.
  • Open Command Prompt and execute the commands below.
    cd D:\Build\Source
    nuget restore YourSolutionFileName.sln
    
2. Downloading (Restoring) packages using MSBuild
  • Execute the commands below.
    "C:\Program Files\Microsoft Visual Studio\2022\Professional\Msbuild\Current\Bin\MSBuild.exe" "../YourSolution.sln" -restore -p:RestorePackagesConfig=true
    
3. Updating packages for a solution using VS Studio Package Manager Console
  • Open Tools > NuGet Package Manager >  Package Manager Console.
  • Execute the commands below.
    Update-Package
4. Reinstalling packages for a solution using VS Studio Package Manager Console
  • Open Tools > NuGet Package Manager >  Package Manager Console.
  • Execute the commands below.
    Update-Package –reinstall
    
5. Configuring package restore when building a project using VS Studio :
  • Open Tools > NuGet Package Manager >  Package Manager Settings.
6. Reverting PackageReference project to packages.config:
  • Copy and  overwrite project file from backup created by Visual Studio or from source control system.
  • Delete all obj and bin files.
7. Fixing “Could not load file or assembly…” issue:
  • Use Visual Studio to verify file or assembly version.
  • Modify web.config to add correct version for the file or assembly.

 

(Visited 2 times, 1 visits today)

Leave a Reply