diff --git a/src/code/InstallPSResource.cs b/src/code/InstallPSResource.cs
index 78e7ecd62..42be06c52 100644
--- a/src/code/InstallPSResource.cs
+++ b/src/code/InstallPSResource.cs
@@ -1,4 +1,3 @@
-using System.Collections.Specialized;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
@@ -26,14 +25,14 @@ class InstallPSResource : PSCmdlet
/// Specifies the exact names of resources to install from a repository.
/// A comma-separated list of module names is accepted. The resource name must match the resource name in the repository.
///
- [Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ParameterSetName = NameParameterSet)]
+ [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = NameParameterSet)]
[ValidateNotNullOrEmpty]
public string[] Name { get; set; }
///
/// Specifies the version or version range of the package to be installed
///
- [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = NameParameterSet)]
[ValidateNotNullOrEmpty]
public string Version { get; set; }
@@ -54,44 +53,58 @@ class InstallPSResource : PSCmdlet
///
/// Specifies a user account that has rights to find a resource from a specific repository.
///
- [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public PSCredential Credential { get; set; }
///
/// Specifies the scope of installation.
///
[Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public ScopeType Scope { get; set; }
///
/// Suppresses being prompted for untrusted sources.
///
[Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public SwitchParameter TrustRepository { get; set; }
///
/// Overwrites a previously installed resource with the same name and version.
///
[Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public SwitchParameter Reinstall { get; set; }
///
/// Suppresses progress information.
///
[Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public SwitchParameter Quiet { get; set; }
///
/// For modules that require a license, AcceptLicense automatically accepts the license agreement during installation.
///
[Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public SwitchParameter AcceptLicense { get; set; }
+ ///
+ /// Used for pipeline input.
+ ///
+ [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = InputObjectParameterSet)]
+ [ValidateNotNullOrEmpty]
+ public PSResourceInfo InputObject { get; set; }
+
#endregion
#region Members
private const string NameParameterSet = "NameParameterSet";
+ private const string InputObjectParameterSet = "InputObjectParameterSet";
private const string RequiredResourceFileParameterSet = "RequiredResourceFileParameterSet";
private const string RequiredResourceParameterSet = "RequiredResourceParameterSet";
List _pathsToInstallPkg;
@@ -107,87 +120,51 @@ protected override void BeginProcessing()
// This is to create a better experience for those who have just installed v3 and want to get up and running quickly
RepositorySettings.CheckRepositoryStore();
- // validate that if a -Version param is passed in that it can be parsed into a NuGet version range.
- // An exact version will be formatted into a version range.
- if (ParameterSetName.Equals(NameParameterSet) && Version != null && !Utils.TryParseVersionOrVersionRange(Version, out _versionRange))
-
- {
- var exMessage = "Argument for -Version parameter is not in the proper format.";
- var ex = new ArgumentException(exMessage);
- var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
- ThrowTerminatingError(IncorrectVersionFormat);
- }
-
- // if no Version specified, install latest version for the package
- if (Version == null)
- {
- _versionRange = VersionRange.All;
- }
-
_pathsToInstallPkg = Utils.GetAllInstallationPaths(this, Scope);
}
protected override void ProcessRecord()
{
- if (!ShouldProcess(string.Format("package to install: '{0}'", String.Join(", ", Name))))
- {
- WriteVerbose(string.Format("Install operation cancelled by user for packages: {0}", String.Join(", ", Name)));
- return;
- }
-
var installHelper = new InstallHelper(updatePkg: false, savePkg: false, cmdletPassedIn: this);
-
switch (ParameterSetName)
{
case NameParameterSet:
- var namesToInstall = Utils.ProcessNameWildcards(Name, out string[] errorMsgs, out bool nameContainsWildcard);
- if (nameContainsWildcard)
+ // If no Version specified, install latest version for the package.
+ // Otherwise validate Version can be parsed out successfully.
+ if (Version == null)
{
- WriteError(new ErrorRecord(
- new PSInvalidOperationException("Name with wildcards is not supported for Install-PSResource cmdlet"),
- "NameContainsWildcard",
- ErrorCategory.InvalidArgument,
- this));
- return;
+ _versionRange = VersionRange.All;
}
-
- foreach (string error in errorMsgs)
+ else if (!Utils.TryParseVersionOrVersionRange(Version, out _versionRange))
{
- WriteError(new ErrorRecord(
- new PSInvalidOperationException(error),
- "ErrorFilteringNamesForUnsupportedWildcards",
- ErrorCategory.InvalidArgument,
- this));
+ var exMessage = "Argument for -Version parameter is not in the proper format.";
+ var ex = new ArgumentException(exMessage);
+ var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
+ ThrowTerminatingError(IncorrectVersionFormat);
}
- // this catches the case where Name wasn't passed in as null or empty,
- // but after filtering out unsupported wildcard names there are no elements left in namesToInstall
- if (namesToInstall.Length == 0)
+ ProcessInstallHelper(installHelper: installHelper,
+ pkgNames: Name,
+ pkgPrerelease: Prerelease,
+ pkgRepository: Repository);
+ break;
+
+ case InputObjectParameterSet:
+ string normalizedVersionString = Utils.GetNormalizedVersionString(InputObject.Version.ToString(), InputObject.PrereleaseLabel);
+ if (!Utils.TryParseVersionOrVersionRange(normalizedVersionString, out _versionRange))
{
- return;
+ var exMessage = String.Format("Version '{0}' for resource '{1}' cannot be parsed.", normalizedVersionString, InputObject.Name);
+ var ex = new ArgumentException(exMessage);
+ var ErrorParsingVersion = new ErrorRecord(ex, "ErrorParsingVersion", ErrorCategory.ParserError, null);
+ WriteError(ErrorParsingVersion);
}
- installHelper.InstallPackages(
- names: namesToInstall,
- versionRange: _versionRange,
- prerelease: Prerelease,
- repository: Repository,
- acceptLicense: AcceptLicense,
- quiet: Quiet,
- reinstall: Reinstall,
- force: false,
- trustRepository: TrustRepository,
- noClobber: false,
- credential: Credential,
- requiredResourceFile: null,
- requiredResourceJson: null,
- requiredResourceHash: null,
- specifiedPath: null,
- asNupkg: false,
- includeXML: true,
- pathsToInstallPkg: _pathsToInstallPkg);
+ ProcessInstallHelper(installHelper: installHelper,
+ pkgNames: new string[] { InputObject.Name },
+ pkgPrerelease: InputObject.IsPrerelease,
+ pkgRepository: new string[]{ InputObject.Repository });
break;
-
+
case RequiredResourceFileParameterSet:
ThrowTerminatingError(new ErrorRecord(
new PSNotImplementedException("RequiredResourceFileParameterSet is not yet implemented. Please rerun cmdlet with other parameter set."),
@@ -211,5 +188,63 @@ protected override void ProcessRecord()
}
#endregion
+
+ #region Methods
+ private void ProcessInstallHelper(InstallHelper installHelper, string[] pkgNames, bool pkgPrerelease, string[] pkgRepository)
+ {
+ var inputNameToInstall = Utils.ProcessNameWildcards(pkgNames, out string[] errorMsgs, out bool nameContainsWildcard);
+ if (nameContainsWildcard)
+ {
+ WriteError(new ErrorRecord(
+ new PSInvalidOperationException("Name with wildcards is not supported for Install-PSResource cmdlet"),
+ "NameContainsWildcard",
+ ErrorCategory.InvalidArgument,
+ this));
+ return;
+ }
+
+ foreach (string error in errorMsgs)
+ {
+ WriteError(new ErrorRecord(
+ new PSInvalidOperationException(error),
+ "ErrorFilteringNamesForUnsupportedWildcards",
+ ErrorCategory.InvalidArgument,
+ this));
+ }
+
+ // this catches the case where Name wasn't passed in as null or empty,
+ // but after filtering out unsupported wildcard names there are no elements left in namesToInstall
+ if (inputNameToInstall.Length == 0)
+ {
+ return;
+ }
+
+ if (!ShouldProcess(string.Format("package to install: '{0}'", String.Join(", ", inputNameToInstall))))
+ {
+ WriteVerbose(string.Format("Install operation cancelled by user for packages: {0}", String.Join(", ", inputNameToInstall)));
+ return;
+ }
+
+ installHelper.InstallPackages(
+ names: pkgNames,
+ versionRange: _versionRange,
+ prerelease: pkgPrerelease,
+ repository: pkgRepository,
+ acceptLicense: AcceptLicense,
+ quiet: Quiet,
+ reinstall: Reinstall,
+ force: false,
+ trustRepository: TrustRepository,
+ noClobber: false,
+ credential: Credential,
+ requiredResourceFile: null,
+ requiredResourceJson: null,
+ requiredResourceHash: null,
+ specifiedPath: null,
+ asNupkg: false,
+ includeXML: true,
+ pathsToInstallPkg: _pathsToInstallPkg);
+ }
+ #endregion
}
}
diff --git a/src/code/SavePSResource.cs b/src/code/SavePSResource.cs
index d4af1d151..be5180150 100644
--- a/src/code/SavePSResource.cs
+++ b/src/code/SavePSResource.cs
@@ -22,7 +22,7 @@ public sealed class SavePSResource : PSCmdlet
#region Members
private const string NameParameterSet = "NameParameterSet";
- private const string InputObjectSet = "InputObjectSet";
+ private const string InputObjectParameterSet = "InputObjectParameterSet";
VersionRange _versionRange;
#endregion
@@ -33,7 +33,7 @@ public sealed class SavePSResource : PSCmdlet
/// Specifies the exact names of resources to save from a repository.
/// A comma-separated list of module names is accepted. The resource name must match the resource name in the repository.
///
- [Parameter(Mandatory = true, Position = 0, ValueFromPipelineByPropertyName = true, ParameterSetName = NameParameterSet)]
+ [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = NameParameterSet)]
[ValidateNotNullOrEmpty]
public string[] Name { get; set; }
@@ -54,15 +54,15 @@ public sealed class SavePSResource : PSCmdlet
/// Specifies the specific repositories to search within.
///
[Parameter(ParameterSetName = NameParameterSet)]
- // todo: add tab completion (look at get-psresourcerepository at the name parameter)
- [ValidateNotNullOrEmpty]
[ArgumentCompleter(typeof(RepositoryNameCompleter))]
+ [ValidateNotNullOrEmpty]
public string[] Repository { get; set; }
///
/// Specifies a user account that has rights to save a resource from a specific repository.
///
- [Parameter(ValueFromPipelineByPropertyName = true, ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public PSCredential Credential { get; set; }
/*
@@ -82,7 +82,8 @@ public sealed class SavePSResource : PSCmdlet
///
/// The destination where the resource is to be installed. Works for all resource types.
///
- [Parameter(ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = "NameParameterSet")]
+ [Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
[ValidateNotNullOrEmpty]
public string Path
{
@@ -109,15 +110,16 @@ public string Path
///
/// Suppresses being prompted for untrusted sources.
///
- [Parameter()]
+ [Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public SwitchParameter TrustRepository { get; set; }
///
/// Used for pipeline input.
///
- [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = InputObjectSet)]
+ [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = InputObjectParameterSet)]
[ValidateNotNullOrEmpty]
- public object[] InputObject { set; get; }
+ public PSResourceInfo InputObject { get; set; }
#endregion
@@ -129,18 +131,6 @@ protected override void BeginProcessing()
// This is to create a better experience for those who have just installed v3 and want to get up and running quickly
RepositorySettings.CheckRepositoryStore();
- // validate that if a -Version param is passed in that it can be parsed into a NuGet version range.
- // an exact version will be formatted into a version range.
- if (ParameterSetName.Equals("NameParameterSet") &&
- Version != null &&
- !Utils.TryParseVersionOrVersionRange(Version, out _versionRange))
- {
- var exMessage = "Argument for -Version parameter is not in the proper format.";
- var ex = new ArgumentException(exMessage);
- var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
- ThrowTerminatingError(IncorrectVersionFormat);
- }
-
// If the user does not specify a path to save to, use the user's current working directory
if (string.IsNullOrWhiteSpace(_path))
{
@@ -150,63 +140,45 @@ protected override void BeginProcessing()
protected override void ProcessRecord()
{
- if (!ShouldProcess(string.Format("Resources to save: '{0}'", String.Join(", ", Name))))
- {
- WriteVerbose(string.Format("Save operation cancelled by user for resources: {0}", String.Join(", ", Name)));
- return;
- }
-
var installHelper = new InstallHelper(updatePkg: false, savePkg: true, cmdletPassedIn: this);
-
switch (ParameterSetName)
{
case NameParameterSet:
- var namesToSave = Utils.ProcessNameWildcards(Name, out string[] errorMsgs, out bool nameContainsWildcard);
- if (nameContainsWildcard)
+ // validate that if a -Version param is passed in that it can be parsed into a NuGet version range.
+ // an exact version will be formatted into a version range.
+ if (Version == null)
{
- WriteError(new ErrorRecord(
- new PSInvalidOperationException("Name with wildcards is not supported for Save-PSResource cmdlet"),
- "NameContainsWildcard",
- ErrorCategory.InvalidArgument,
- this));
- return;
+ _versionRange = VersionRange.All;
}
-
- foreach (string error in errorMsgs)
+ else if (!Utils.TryParseVersionOrVersionRange(Version, out _versionRange))
{
- WriteError(new ErrorRecord(
- new PSInvalidOperationException(error),
- "ErrorFilteringNamesForUnsupportedWildcards",
- ErrorCategory.InvalidArgument,
- this));
+ var exMessage = "Argument for -Version parameter is not in the proper format.";
+ var ex = new ArgumentException(exMessage);
+ var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
+ ThrowTerminatingError(IncorrectVersionFormat);
}
- // this catches the case where Name wasn't passed in as null or empty,
- // but after filtering out unsupported wildcard names there are no elements left in namesToSave
- if (namesToSave.Length == 0)
+ ProcessSaveHelper(installHelper: installHelper,
+ pkgNames: Name,
+ pkgPrerelease: Prerelease,
+ pkgRepository: Repository);
+ break;
+
+ case InputObjectParameterSet:
+ string normalizedVersionString = Utils.GetNormalizedVersionString(InputObject.Version.ToString(), InputObject.PrereleaseLabel);
+ if (!Utils.TryParseVersionOrVersionRange(normalizedVersionString, out _versionRange))
{
- return;
+ var exMessage = String.Format("Version '{0}' for resource '{1}' cannot be parsed.", normalizedVersionString, InputObject.Name);
+ var ex = new ArgumentException(exMessage);
+ var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
+ ThrowTerminatingError(IncorrectVersionFormat);
}
-
- installHelper.InstallPackages(
- names: namesToSave,
- versionRange: _versionRange,
- prerelease: Prerelease,
- repository: Repository,
- acceptLicense: true,
- quiet: true,
- reinstall: true,
- force: false,
- trustRepository: TrustRepository,
- noClobber: false,
- credential: Credential,
- requiredResourceFile: null,
- requiredResourceJson: null,
- requiredResourceHash: null,
- specifiedPath: _path,
- asNupkg: false,
- includeXML: false,
- pathsToInstallPkg: new List { _path } );
+
+ ProcessSaveHelper(installHelper: installHelper,
+ pkgNames: new string[] { InputObject.Name },
+ pkgPrerelease: InputObject.IsPrerelease,
+ pkgRepository: new string[] { InputObject.Repository });
+
break;
default:
@@ -216,5 +188,63 @@ protected override void ProcessRecord()
}
#endregion
+
+ #region Methods
+ private void ProcessSaveHelper(InstallHelper installHelper, string[] pkgNames, bool pkgPrerelease, string[] pkgRepository)
+ {
+ var namesToSave = Utils.ProcessNameWildcards(pkgNames, out string[] errorMsgs, out bool nameContainsWildcard);
+ if (nameContainsWildcard)
+ {
+ WriteError(new ErrorRecord(
+ new PSInvalidOperationException("Name with wildcards is not supported for Save-PSResource cmdlet"),
+ "NameContainsWildcard",
+ ErrorCategory.InvalidArgument,
+ this));
+ return;
+ }
+
+ foreach (string error in errorMsgs)
+ {
+ WriteError(new ErrorRecord(
+ new PSInvalidOperationException(error),
+ "ErrorFilteringNamesForUnsupportedWildcards",
+ ErrorCategory.InvalidArgument,
+ this));
+ }
+
+ // this catches the case where Name wasn't passed in as null or empty,
+ // but after filtering out unsupported wildcard names there are no elements left in namesToSave
+ if (namesToSave.Length == 0)
+ {
+ return;
+ }
+
+ if (!ShouldProcess(string.Format("Resources to save: '{0}'", namesToSave)))
+ {
+ WriteVerbose(string.Format("Save operation cancelled by user for resources: {0}", namesToSave));
+ return;
+ }
+
+ installHelper.InstallPackages(
+ names: namesToSave,
+ versionRange: _versionRange,
+ prerelease: pkgPrerelease,
+ repository: pkgRepository,
+ acceptLicense: true,
+ quiet: true,
+ reinstall: true,
+ force: false,
+ trustRepository: TrustRepository,
+ noClobber: false,
+ credential: Credential,
+ requiredResourceFile: null,
+ requiredResourceJson: null,
+ requiredResourceHash: null,
+ specifiedPath: _path,
+ asNupkg: false,
+ includeXML: false,
+ pathsToInstallPkg: new List { _path } );
+ }
+ #endregion
}
}
diff --git a/src/code/UninstallPSResource.cs b/src/code/UninstallPSResource.cs
index e38cd7533..36d16a1a0 100644
--- a/src/code/UninstallPSResource.cs
+++ b/src/code/UninstallPSResource.cs
@@ -25,7 +25,7 @@ public sealed class UninstallPSResource : PSCmdlet
/// Specifies the exact names of resources to uninstall.
/// A comma-separated list of module names is accepted. The resource name must match the resource name in the repository.
///
- [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = NameParameterSet)]
+ [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = NameParameterSet)]
[ValidateNotNullOrEmpty]
public string[] Name { get; set; }
@@ -39,19 +39,20 @@ public sealed class UninstallPSResource : PSCmdlet
///
/// Used for pipeline input.
///
- [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, ParameterSetName = InputObjectSet)]
+ [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ParameterSetName = InputObjectParameterSet)]
[ValidateNotNullOrEmpty]
- public PSResourceInfo[] InputObject { get; set; }
+ public PSResourceInfo InputObject { get; set; }
///
///
[Parameter(ParameterSetName = NameParameterSet)]
+ [Parameter(ParameterSetName = InputObjectParameterSet)]
public SwitchParameter Force { get; set; }
#endregion
#region Members
private const string NameParameterSet = "NameParameterSet";
- private const string InputObjectSet = "InputObjectSet";
+ private const string InputObjectParameterSet = "InputObjectParameterSet";
public static readonly string OsPlatform = System.Runtime.InteropServices.RuntimeInformation.OSDescription;
VersionRange _versionRange;
List _pathsToSearch = new List();
@@ -60,22 +61,6 @@ public sealed class UninstallPSResource : PSCmdlet
#region Methods
protected override void BeginProcessing()
{
- // validate that if a -Version param is passed in that it can be parsed into a NuGet version range.
- // an exact version will be formatted into a version range.
- if (ParameterSetName.Equals("NameParameterSet") && Version != null && !Utils.TryParseVersionOrVersionRange(Version, out _versionRange))
- {
- var exMessage = "Argument for -Version parameter is not in the proper format.";
- var ex = new ArgumentException(exMessage);
- var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
- ThrowTerminatingError(IncorrectVersionFormat);
- }
-
- // if no Version specified, uninstall all versions for the package
- if (Version == null)
- {
- _versionRange = VersionRange.All;
- }
-
_pathsToSearch = Utils.GetAllResourcePaths(this);
}
@@ -84,6 +69,21 @@ protected override void ProcessRecord()
switch (ParameterSetName)
{
case NameParameterSet:
+ // if no Version specified, uninstall all versions for the package.
+ // validate that if a -Version param is passed in that it can be parsed into a NuGet version range.
+ // an exact version will be formatted into a version range.
+ if (Version == null)
+ {
+ _versionRange = VersionRange.All;
+ }
+ else if (!Utils.TryParseVersionOrVersionRange(Version, out _versionRange))
+ {
+ var exMessage = "Argument for -Version parameter is not in the proper format.";
+ var ex = new ArgumentException(exMessage);
+ var IncorrectVersionFormat = new ErrorRecord(ex, "IncorrectVersionFormat", ErrorCategory.InvalidArgument, null);
+ ThrowTerminatingError(IncorrectVersionFormat);
+ }
+
Name = Utils.ProcessNameWildcards(Name, out string[] errorMsgs, out bool _);
foreach (string error in errorMsgs)
@@ -109,34 +109,25 @@ protected override void ProcessRecord()
}
break;
- case InputObjectSet:
- // the for loop will use type PSObject in order to pull the properties from the pkg object
- foreach (PSResourceInfo pkg in InputObject)
+ case InputObjectParameterSet:
+ if (!Utils.TryParseVersionOrVersionRange(InputObject.Version.ToString(), out _versionRange))
{
- if (pkg == null)
- {
- continue;
- }
-
- // attempt to parse version
- if (!Utils.TryParseVersionOrVersionRange(pkg.Version.ToString(), out VersionRange _versionRange))
- {
- var exMessage = String.Format("Version '{0}' for resource '{1}' cannot be parsed.", pkg.Version.ToString(), pkg.Name);
- var ex = new ArgumentException(exMessage);
- var ErrorParsingVersion = new ErrorRecord(ex, "ErrorParsingVersion", ErrorCategory.ParserError, null);
- WriteError(ErrorParsingVersion);
- }
-
- Name = new string[] { pkg.Name };
- if (!String.IsNullOrWhiteSpace(pkg.Name) && !UninstallPkgHelper())
- {
- // specific errors will be displayed lower in the stack
- var exMessage = String.Format(string.Format("Did not successfully uninstall package {0}", pkg.Name));
- var ex = new ArgumentException(exMessage);
- var UninstallResourceError = new ErrorRecord(ex, "UninstallResourceError", ErrorCategory.InvalidOperation, null);
- WriteError(UninstallResourceError);
- }
+ var exMessage = String.Format("Version '{0}' for resource '{1}' cannot be parsed.", InputObject.Version.ToString(), InputObject.Name);
+ var ex = new ArgumentException(exMessage);
+ var ErrorParsingVersion = new ErrorRecord(ex, "ErrorParsingVersion", ErrorCategory.ParserError, null);
+ WriteError(ErrorParsingVersion);
}
+
+ Name = new string[] { InputObject.Name };
+ if (!String.IsNullOrWhiteSpace(InputObject.Name) && !UninstallPkgHelper())
+ {
+ // specific errors will be displayed lower in the stack
+ var exMessage = String.Format(string.Format("Did not successfully uninstall package {0}", InputObject.Name));
+ var ex = new ArgumentException(exMessage);
+ var UninstallResourceError = new ErrorRecord(ex, "UninstallResourceError", ErrorCategory.InvalidOperation, null);
+ WriteError(UninstallResourceError);
+ }
+
break;
default:
@@ -162,7 +153,6 @@ private bool UninstallPkgHelper()
// note that the xml file is located in ./Scripts/InstalledScriptInfos, eg: ./Scripts/InstalledScriptInfos/TestScript_InstalledScriptInfo.xml
string pkgName = string.Empty;
-
foreach (string pkgPath in getHelper.FilterPkgPathsByVersion(_versionRange, dirsToDelete))
{
pkgName = Utils.GetInstalledPackageName(pkgPath);
diff --git a/test/InstallPSResource.Tests.ps1 b/test/InstallPSResource.Tests.ps1
index 9dcfa1f30..fd8be4ba2 100644
--- a/test/InstallPSResource.Tests.ps1
+++ b/test/InstallPSResource.Tests.ps1
@@ -9,6 +9,7 @@ Describe 'Test Install-PSResource for Module' {
$TestGalleryName = Get-PoshTestGalleryName
$PSGalleryName = Get-PSGalleryName
$NuGetGalleryName = Get-NuGetGalleryName
+ $testModuleName = "TestModule"
Get-NewPSResourceRepositoryFile
Register-LocalRepos
}
@@ -251,6 +252,13 @@ Describe 'Test Install-PSResource for Module' {
$res = Get-Module "testModuleWithScript" -ListAvailable
$res.Path.Contains("Modules") | Should -Be $true
}
+
+ It "Install PSResourceInfo object piped in" {
+ Find-PSResource -Name $testModuleName -Version "1.1.0.0" -Repository $TestGalleryName | Install-PSResource
+ $res = Get-InstalledPSResource -Name $testModuleName
+ $res.Name | Should -Be $testModuleName
+ $res.Version | Should -Be "1.1.0.0"
+ }
}
<# Temporarily commented until -Tag is implemented for this Describe block
diff --git a/test/SavePSResource.Tests.ps1 b/test/SavePSResource.Tests.ps1
index 7f107b21f..910597f7e 100644
--- a/test/SavePSResource.Tests.ps1
+++ b/test/SavePSResource.Tests.ps1
@@ -9,6 +9,7 @@ Describe 'Test Save-PSResource for PSResources' {
$TestGalleryName = Get-PoshTestGalleryName
$PSGalleryName = Get-PSGalleryName
$NuGetGalleryName = Get-NuGetGalleryName
+ $testModuleName = "test_module"
Get-NewPSResourceRepositoryFile
Register-LocalRepos
@@ -173,6 +174,20 @@ Describe 'Test Save-PSResource for PSResources' {
(Get-ChildItem -Path $pkgDir.FullName).Count | Should -Be 1
}
+ It "Save PSResourceInfo object piped in" {
+ Find-PSResource -Name "TestModule" -Version "1.1.0.0" -Repository $TestGalleryName | Save-PSResource -Path $SaveDir
+ $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq "TestModule"
+ $pkgDir | Should -Not -BeNullOrEmpty
+ (Get-ChildItem -Path $pkgDir.FullName).Count | Should -Be 1
+ }
+
+ It "Save PSResourceInfo object piped in for prerelease version object" {
+ Find-PSResource -Name $testModuleName -Version "4.5.2-alpha001" -Repository $TestGalleryName | Save-PSResource -Path $SaveDir
+ $pkgDir = Get-ChildItem -Path $SaveDir | Where-Object Name -eq $testModuleName
+ $pkgDir | Should -Not -BeNullOrEmpty
+ (Get-ChildItem -Path $pkgDir.FullName).Count | Should -Be 1
+ }
+
<#
# Tests should not write to module directory
It "Save specific module resource by name if no -Path param is specifed" {
diff --git a/test/UninstallPSResource.Tests.ps1 b/test/UninstallPSResource.Tests.ps1
index f20e967ae..8f5f6a9f9 100644
--- a/test/UninstallPSResource.Tests.ps1
+++ b/test/UninstallPSResource.Tests.ps1
@@ -8,6 +8,7 @@ Describe 'Test Uninstall-PSResource for Modules' {
BeforeAll{
$TestGalleryName = Get-PoshTestGalleryName
$PSGalleryName = Get-PSGalleryName
+ $testModuleName = "test_module"
Get-NewPSResourceRepositoryFile
$res = Uninstall-PSResource -name ContosoServer -Version "*"
}
@@ -162,4 +163,21 @@ Describe 'Test Uninstall-PSResource for Modules' {
$pkg = Get-Module "RequiredModule1" -ListAvailable
$pkg | Should -Be $null
}
+
+ It "Uninstall PSResourceInfo object piped in" {
+ Install-PSResource -Name "ContosoServer" -Version "1.5.0.0" -Repository $TestGalleryName
+ Get-InstalledPSResource -Name "ContosoServer" -Version "1.5.0.0" | Uninstall-PSResource
+ $res = Get-InstalledPSResource -Name "ContosoServer" -Version "1.5.0.0"
+ $res | Should -BeNullOrEmpty
+ }
+
+ It "Uninstall PSResourceInfo object piped in for prerelease version object" {
+ Install-PSResource -Name $testModuleName -Version "4.5.2-alpha001" -Repository $TestGalleryName
+ # Powershell cannot create install locations indicating a prerelease version (with prerelease label indicated in install location).
+ # To test we can uninstall prerelease versions, we must use the numeric part of the prerelease version only and it must be unique
+ # of all versions installed for that module.
+ Get-InstalledPSResource -Name $testModuleName -Version "4.5.2" | Uninstall-PSResource
+ $res = Get-InstalledPSResource -Name $testModuleName -Version "4.5.2"
+ $res | Should -BeNullOrEmpty
+ }
}