-
Notifications
You must be signed in to change notification settings - Fork 189
PackageProvider Interface
###Overview (c#)### You may try out a sample C# based provider: https://github.com/OneGet/NuGetProvider. To create your own provider, download the sdk https://github.com/OneGet/ProviderSdk, add your business logic and test it. Once you are ready for others to consume your provider, you may follow the guidance https://github.com/OneGet/oneget/wiki/How-to-submit-your-provider to submit it.
A PackageManagement PackageProvider
that is implemented in C# must expose functions with signatures that match the following:
string PackageProviderName;
string ProviderVersion;
void InitializeProvider(Request request);
void GetFeatures(Request request);
void GetDynamicOptions(string category, Request request);
void ResolvePackageSources(Request request);
void AddPackageSource(string name, string location, bool trusted, Request request);
void RemovePackageSource(string name, Request request);
int StartFind(Callback c);
bool CompleteFind(int id, Callback c);
void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request r)
void FindPackageByFile(string file, int id, Request request)
void DownloadPackage(string fastPackageReference, string destLocation, Request request)
void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, Request r)
void InstallPackage(string fastPackageReference, Request request)
void UninstallPackage(string fastPackageReference, Request request)
###Overview (PowerShell)###
For the PowerShell based package provider, you may try out a sample PowerShell based provider: https://github.com/OneGet/MyAlbum-Sample-Provider.
A PackageManagement PackageProvider
that is implemented in PowerShell must be written as a module that exposes functions with signatures that match the following:
function Get-PackageProviderName
{
#your code
}
function Initialize-Provider
{
#your code
}
function Get-Feature
{
#your code
}
function Get-DynamicOptions
{
param
(
[Microsoft.PackageManagement.MetaProvider.PowerShell.OptionCategory]
$category
)
#your code
}
function Add-PackageSource
{
[CmdletBinding()]
param
(
[string]
$Name,
[string]
$Location,
[bool]
$Trusted
)
#your code
}
function Remove-PackageSource
{
param
(
[string]
$Name
)
#your code
}
function Resolve-PackageSource
{
#your code
}
function Find-Package {
param(
[string] $name,
[string] $requiredVersion,
[string] $minimumVersion,
[string] $maximumVersion
)
#your code
}
function Download-Package
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$FastPackageReference,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$Location
)
#your code
}
function Install-Package
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$fastPackageReference
)
#your code
}
function UnInstall-Package
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$fastPackageReference
)
#your code
}
function Get-InstalledPackage
{
[CmdletBinding()]
param
(
[Parameter()]
[string]
$Name,
[Parameter()]
[string]
$RequiredVersion,
[Parameter()]
[string]
$MinimumVersion,
[Parameter()]
[string]
$MaximumVersion
)
#your code
}
Returns the name of this PackageProvider
This is required. Without this, the PackageProvider
implementation will not be recognized, and will not load.
string PackageProviderName { }
function Get-PackageProviderName { }
As string
representing the name for this package provider. This value is exposed to the user.
If the PackageProvider
has a failure, it should throw an exception.
Adds a (or replaces an existing) package source.
Package Sources are always managed by the PackageProvider
.
This function is required if the PackageProvider
supports user-specified package sources
void AddPackageSource(string name, string location, bool trusted, Request request);
function Add-PackageSource
{
[CmdletBinding()]
param
(
[string]
$Name,
[string]
$Location,
[bool]
$Trusted
)
}
Parameter | Type | Description |
---|---|---|
name |
string |
the name the user is giving to the package source |
location |
string |
the location that the source points to. (Uri, Filepath, or any other destination format supported by the package provider) |
trusted |
bool |
Indicates whether the user trusts packages from this source |
If a package source is added or updated, the PackageProvider
must call request.YieldPackageSource( )
with the details regarding the package source
- Powershell-specific
Instead of calling$request.YieldPackageSource( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.PackageSource
object.
There is no return value from this function.
If the PackageProvider
is unable to fulfill add the source, it should throw an exception.
Removes an existing package source.
Package Sources are always managed by the PackageProvider
.
This function is required if the PackageProvider
supports user-specified package sources
void RemovePackageSource(string name, Request request)
function Remove-PackageSource {
param(
[string] $name,
)
}
Parameter | Type | Description |
---|---|---|
name |
string |
the name of the package source the user wants to remove |
If a package source is removed the PackageProvider
must call request.YieldPackageSource( )
with the details regarding the package source that was removed.
- Powershell-specific
Instead of calling$request.YieldPackageSource( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.PackageSource
object.
There is no return value from this function.
If the PackageProvider
is unable to remove the source, it should throw an exception.
If the PackageProvider
is does not have a source with that name, no exception should be thrown.
Finds packages given name
If the PackageProvider
supports searching for packages given a name, this method is required.
void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request req);
function Find-Package {
param(
[string] $name,
[string] $requiredVersion,
[string] $minimumVersion,
[string] $maximumVersion
)
}
# Alternative, accepts multiple names as first parameter
function Find-Package {
param(
[string[]] $names,
[string] $requiredVersion,
[string] $minimumVersion,
[string] $maximumVersion
)
}
Parameter | Type | Description |
---|---|---|
name |
string |
a singular string name to search for a package. Any wildcards must be handled by the PackageProvider
|
names (PowerShell only) |
string[] |
an array of strings name to search for a package. Any wildcards must be handled by the PackageProvider
|
requiredVersion |
string |
the exact version the user is requesting. if this is null or empty, the user has not specified a specific version |
minimumVersion |
string |
the minimum version the user is requesting. if this is null or empty, the user has not specified a minimum version |
maximumVersion |
string |
the maximum version the user is requesting. if this is null or empty, the user has not specified a maximum version |
id |
int |
reserved |
Additional options about the request can be retrieved from the Request
object.
-
Dynamic options
Request.Options
returns aHashtable
of the all the dynamic options passed into the request.Request.PackageSources
returns the collection of the package sources the user requested, or an empty collection if the user did not specify package sources. -
Powershell Specific options
$request.PSCredential
returns any credential object passed in from the user. Null if not specified -
.NET Specific options
Request.CredentialName
returns a the name of the credential object passed in from the user. Null if not specifiedRequest.CredentialPassword
returns a the password (as aSecureString
) of the credential object passed in from the user. Null if not specified.
For each package found, the PackageProvider
must call request.YieldPackage( )
with the details regarding the package.
- Powershell-specific
Instead of calling$request.YieldPackage( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.SoftwareIdentity
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. Finding 0 results must not throw an exception.
Finds packages given a path to a specific file
If the PackageProvider
supports searching for packages given a file, this method is required.
void FindPackageByFile(string file, int id, Request request)
function Find-PackageByFile {
param(
[string] $filePath,
)
}
# Alternative, accepts multiple names as first parameter
function Find-PackageByFile {
param(
[string[]] $filePaths,
)
}
Parameter | Type | Description |
---|---|---|
filePath |
string |
a singular string file path to resolve to a package. |
filePaths (PowerShell only) |
string[] |
an array of strings for file paths to resolve to a package. |
id |
int |
reserved |
Additional options about the request can be retrieved from the Request
object.
-
Dynamic options
Request.Options
returns aHashtable
of the all the dynamic options passed into the request. -
Powershell Specific options
$request.PSCredential
returns any credential object passed in from the user. Null if not specified -
.NET Specific options
Request.CredentialName
returns a the name of the credential object passed in from the user. Null if not specifiedRequest.CredentialPassword
returns a the password (as aSecureString
) of the credential object passed in from the user. Null if not specified.
For each package found, the PackageProvider
must call request.YieldPackage( )
with the details regarding the package.
- Powershell-specific
Instead of calling$request.YieldPackage( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.SoftwareIdentity
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. Finding 0 results must not throw an exception.
Finds packages given a URI
If the PackageProvider
supports searching for packages given an URI, this method is required.
void FindPackageByUri(Uri location, Request request);
function Find-PackageByUri {
param(
[Uri] $location,
)
}
# Alternative, accepts multiple names as first parameter
function Find-PackageByUri {
param(
[Uri[]] $locations,
)
}
Parameter | Type | Description |
---|---|---|
location |
Uri |
a URI to an expected package location. |
locations (PowerShell only) |
Uri[] |
an array of URIs to expected package locations. |
Additional options about the request can be retrieved from the Request
object.
-
Dynamic options
Request.Options
returns aHashtable
of the all the dynamic options passed into the request. -
Powershell Specific options
$request.PSCredential
returns any credential object passed in from the user. Null if not specified -
.NET Specific options
Request.CredentialName
returns a the name of the credential object passed in from the user. Null if not specifiedRequest.CredentialPassword
returns a the password (as aSecureString
) of the credential object passed in from the user. Null if not specified.
For each package found, the PackageProvider
must call request.YieldPackage( )
with the details regarding the package.
- Powershell-specific
Instead of calling$request.YieldPackage( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.SoftwareIdentity
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. Finding 0 results must not throw an exception.
Gets the installed packages
If the PackageProvider
can detect if a package is installed, it should implement this function.
void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, Request req);
function Get-InstalledPackage
{
[CmdletBinding()]
param
(
[Parameter()]
[string]
$Name,
[Parameter()]
[Version]
$RequiredVersion,
[Parameter()]
[Version]
$MinimumVersion,
[Parameter()]
[Version]
$MaximumVersion
)
Parameter | Type | Description |
---|---|---|
name |
string |
a name of a package to match. if this is null or empty, the user did not specify a package to match. |
requiredVersion |
string |
the exact version the user is requesting. if this is null or empty, the user has not specified a specific version |
minimumVersion |
string |
the minimum version the user is requesting. if this is null or empty, the user has not specified a minimum version |
maximumVersion |
string |
the maximum version the user is requesting. if this is null or empty, the user has not specified a maximum version |
Additional options about the request can be retrieved from the Request
object.
-
Dynamic options
Request.Options
returns aHashtable
of the all the dynamic options passed into the request. -
Powershell Specific options
$request.PSCredential
returns any credential object passed in from the user. Null if not specified -
.NET Specific options
Request.CredentialName
returns a the name of the credential object passed in from the user. Null if not specifiedRequest.CredentialPassword
returns a the password (as aSecureString
) of the credential object passed in from the user. Null if not specified.
For each installed package found, the PackageProvider
must call request.YieldPackage( )
with the details regarding the package.
- Powershell-specific
Instead of calling$request.YieldPackage( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.SoftwareIdentity
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. Finding 0 results must not throw an exception.
Gets the dynamic options for a specified operation
If the PackageProvider
wishes to allow the user to specify additional options, this function must be implemented.
void GetDynamicOptions(OptionCategory category, Request request);
function Get-Options{
param(
[OptionCategory] $category
)
}
Parameter | Type | Description |
---|---|---|
category |
OptionCategory |
the category of options that the host is requesting (See [[OptionCategory enum |
None.
For each installed package found, the PackageProvider
must call request.YieldDynamicOption( )
with the details of the dynamic option.
- Powershell-specific
Instead of calling$request.YieldDynamicOption( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.DynamicOption
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. If there are no dynamic options for the category, this must not throw an exception.
Gets the registered package sources that this provider is aware of.
If the PackageProvider
supports user-specified package sources, this function should be implemented.
void GetPackageSources(Request request);
function Get-PackageSources{
param(
)
}
None.
None.
For each installed package found, the PackageProvider
must call request.YieldPackageSource( )
with the details of the dynamic option.
- Powershell-specific
Instead of calling$request.YieldPackageSource( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.PackageSource
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. If there are no registered package sources for this proivder, this must not throw an exception.
Allows the provider to do one-time initialization.
If the PackageProvider
requires one-time initialization at provider load-time, this function is required.
void InitializeProvider(Request request);
function Initialize-Provider{
param(
)
}
None.
None.
None.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception. If an exception is thrown from this function, the provider will not be loaded.
Installs a package
If the PackageProvider
can install packages, this function must be implemented.
void InstallPackage(string fastPackageReference, Request request);
function Install-Package{
param(
[string] fastPackageReference
)
}
Parameter | Type | Description |
---|---|---|
fastPackageReference |
string |
a string (originally obtained from this PackageProvider via a call to one of the FindPackage* methods) that the Provider can use to uniquely reconstitute the specific package information. (i.e., the data required to quickly find a specific package again, serialized to a string) |
-
Dynamic options
Request.Options
returns aHashtable
of the all the dynamic options passed into the request. -
Powershell Specific options
$request.PSCredential
returns any credential object passed in from the user. Null if not specified -
.NET Specific options
Request.CredentialName
returns a the name of the credential object passed in from the user. Null if not specifiedRequest.CredentialPassword
returns a the password (as aSecureString
) of the credential object passed in from the user. Null if not specified.
For each package installed, the PackageProvider
must call request.YieldPackage( )
with the details regarding the package.
- Powershell-specific
Instead of calling$request.YieldPackage( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.SoftwareIdentity
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception.
Uninstalls a package
If the PackageProvider
can install packages, this function must be implemented.
void UninstallPackage(string fastPackageReference, Request request);
function Uninstall-Package{
param(
[string] fastPackageReference
)
}
Parameter | Type | Description |
---|---|---|
fastPackageReference |
string |
a string (originally obtained from this PackageProvider via a call to the GetInstalledPackage method) that the Provider can use to uniquely reconstitute the specific package information. (i.e., the data required to quickly find a specific package again, serialized to a string) |
-
Dynamic options
Request.Options
returns aHashtable
of the all the dynamic options passed into the request. -
Powershell Specific options
$request.PSCredential
returns any credential object passed in from the user. Null if not specified -
.NET Specific options
Request.CredentialName
returns a the name of the credential object passed in from the user. Null if not specifiedRequest.CredentialPassword
returns a the password (as aSecureString
) of the credential object passed in from the user. Null if not specified.
For each package removed, the PackageProvider
must call request.YieldPackage( )
with the details regarding the package.
- Powershell-specific
Instead of calling$request.YieldPackage( )
, PowerShell-based providers can simplyWrite-Output
an instance of aMicrosoft.OneGet.PowerShell.SoftwareIdentity
object.
There is no return value from this function.
If the PackageProvider
encounters an unexpected error, it should throw an exception.
If the provider is asked to uninstall a package is not currently installed, this should not throw an exception.