ARTIFACTORY: How to install NuGet modules using PowerShell?
Artifactory supports NuGet module installation via the PowerShell client. As a first step, we'll set up a few parameters that will be utilized in the subsequent commands to set up Artifactory as a source:
- Name - the name of the Repository to register.
- SourceLocation - the Artifactory URL for resolving the modules.
- InstallationPolicy - specifies the installation policy (can be either Trusted or Untrusted).
- Credential - the Artifactory username.
- PackageManagementProvider - specifies a package management provider.
- Verbose - enable verbose output.
We will set these parameters in the $artParams variable:
PS C:\Windows\system32> $artParams=@{
Name = 'Artifactory'
SourceLocation = 'https://ART_HOST/artifactory/api/nuget/powershell-virtual'
InstallationPolicy = 'Trusted'
PublishLocation = 'https://ART_HOST/artifactory/api/nuget/powershell-virtual'
PackageManagementProvider = 'NuGet'
Verbose = $True
}
Note: ART_HOST in the above example should be replaced with your actual Artifactory hostname.
In addition, the remote NuGet repository should be pointing to https://www.powershellgallery.com.
Next, we will register the Artifactory repository using the $artParams variable we set earlier and the Register-PSRepository command and then set it using the Set-PSRepository command:
PS C:\Windows\system32> Register-PSRepository @repoParams PS C:\Windows\system32> Set-PSRepository -name Artifactory -InstallationPolicy trusted -verbose
To make sure that the Artifactory repository is configured correctly, we can run the Find-Modules command to see the available modules. For instance, in this call, we will search for the “Foil” module:
PS C:\Windows\system32> Find-Module -Repository Artifactory -Name Foil
Lastly, the module can be installed using the Install-Module command:
PS C:\Windows\system32> Install-Module -Repository Artifactory -Name Foil
More information on the above PowerShell commands can be found in the following external links: