Installing NuGet packages
This post describes three examples of installing /re-installing NuGet packages. That is:
- Re-install a NuGet package manually
- Install NuGet packages from NuGet, via a PowerShell script
- Install NuGet packages from a local artifact feed, via a PowerShell script
1.) Re-install a NuGet package manually
a.) Connect to NuGet

Setup Visual Studio so that it can connect to NuGet

b.) Determine which version of the package is required to be re-installed

c.) Install the package

The missing package is then placed in the packages folder i.e. …\packages\Microsoft.CrmSdk.CoreAssemblies.9.0.2.5\lib\net452\Microsoft.Crm.Sdk.Proxy.dll & Microsoft.Xrm.Sdk.dll
2.) Install NuGet packages via a PowerShell script
a.) Connect to NuGet
Packages can also be downloaded from NuGet by executing the following PowerShell script ‘Install packages.ps1’.
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = ".\nuget.exe"
if((Test-Path -Path $targetNugetExe) -eq $false)
{
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
}
Set-Alias nuget $targetNugetExe -Scope Global
./nuget restore packages.config -PackagesDirectory packages
The script downloads nuget.exe if it doesn’t already exist on the file system. It then downloads any packages that are listed in packages.config

b.) Connect to a local artifact feed
Packages can also be created, stored and downloaded from a local Artifact feed.
In this example:
- the local Artifact feed contoso-common-packages contains the NuGet package contosoCmdlets

- this NuGet package can be downloaded by executing the following PowerShell script ‘Install Contoso Tools.ps1’.
$version = "0.0.1.13";
$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$targetNugetExe = ".\nuget.exe"
if((Test-Path -Path $targetNugetExe) -eq $false)
{
Write-Host "Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe"
Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe
}
Set-Alias nuget $targetNugetExe -Scope Global
Write-Host "./nuget install ContosoCmdlets -Version $version -Source https://pkgs.dev.azure.com/.../_packaging/contoso-common-packages/nuget/v3/index.json -OutputDirectory ./packages"
./nuget install ContosoCmdlets -Version $version -Source https://pkgs.dev.azure.com/.../_packaging/contoso-common-packages/nuget/v3/index.json -OutputDirectory ./packages
The location of the package is displayed in Figure 7
