Sunday, August 2, 2015

Setup your Chocolatey repository in Azure - Part 3

PackageManagement (previously referred as OneGet) is a new feature introduced in PowerShell 5.0 to discover and install software packages from around the web. It is a manager or multiplexor of existing package managers (also called package providers) that unifies Windows package management with a single Windows PowerShell interface. With PackageManagement, you can do the following.

Manage a list of software repositories in which packages can be searched, acquired, and installed
Discover software packages you need

Seamlessly install, uninstall, and inventory packages from one or more software repositories
To see the commands supported by PackageManagement, use the Get-Command as given below.


PS C:\> Get-Command -Module PackageManagement | ft -Property Name, Version, Source

Name                     Version Source          
----                     ------- ------          
Find-Package             1.0.0.0 PackageManagement
Get-Package              1.0.0.0 PackageManagement
Get-PackageProvider      1.0.0.0 PackageManagement
Get-PackageSource        1.0.0.0 PackageManagement
Install-Package          1.0.0.0 PackageManagement
Register-PackageSource   1.0.0.0 PackageManagement
Save-Package             1.0.0.0 PackageManagement
Set-PackageSource        1.0.0.0 PackageManagement
Uninstall-Package        1.0.0.0 PackageManagement
Unregister-PackageSource 1.0.0.0 PackageManagement


By default a set of providers with sources are configured in PackageManagement. You can use the Get-PackageSource cmdlet to see the available sources.


PS C:\> Get-PackageProvider | select name

Name     
----     
msu      
Programs 
msi      
PSModule 
Chocolatey
NuGet     



PS C:\> Get-PackageSource -ProviderName Chocolatey | ft ProviderName, IsTrusted, IsRegistered, Location

ProviderName IsTrusted IsRegistered Location                    
------------ --------- ------------ --------                    
Chocolatey       False         True http://chocolatey.org/api/v2/


Each PackageManagement provider may have one or multiple software sources, or repositories. The Get-PackageSource cmdlet can be used to discover what repositories are associated with a provider. For e.g. to see the sources associated with the Chocolatey provider use the cmdlet as given below. The Register-PackageSource cmdlet can be used to add a new source to the existing provider. We'll use this cmdlet to register the Chocolatey source we created in the previous post to the PackageManagement provider as given below.



PS C:\> Register-PackageSource –provider Chocolatey –name AzureChoco –location http://prajeeshchoco.azurewebsites.net/nuget

Name                             ProviderName     IsTrusted  IsRegistered IsValidated  Location                                                        
----                             ------------     ---------  ------------ -----------  --------                                                         
AzureChoco                       Chocolatey       False      True         True         http://prajeeshchoco.azurewebsites.net/nuget                    



PS C:\> Get-PackageSource -ProviderName Chocolatey | ft ProviderName, IsTrusted, IsRegistered, Location

ProviderName IsTrusted IsRegistered Location                                   
------------ --------- ------------ --------                                   
Chocolatey       False         True http://chocolatey.org/api/v2/              
Chocolatey       False         True http://prajeeshchoco.azurewebsites.net/nuget  



We’ve successfully registered our Chocolatey repository to the source, we can now find and install packages using the PackageManagement as  given.


PS C:\> Find-Package -Source AzureChoco | ft Name, Version, source

Name Version Source   
---- ------- ------   
Foxe 1.2.0   AzureChoco



No comments: