Skip to content

Commit a199d72

Browse files
authored
Fix for Install-PSResource always reinstall issue (PowerShell#525)
* Fix for always reinstall issue and general clean up * Added restore option for reinstall, in case the install fails
1 parent d121ded commit a199d72

13 files changed

Lines changed: 310 additions & 206 deletions

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
MIT License
1+
Copyright (c) Microsoft Corporation.
22

3-
Copyright (c) 2020 PowerShell Team
3+
MIT License
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

doBuild.ps1

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ function DoBuild
3636
Write-Verbose -Verbose -Message "Copying help files to '$BuildOutPath'"
3737
Copy-Item -Path "${HelpPath}/${Culture}" -Dest "$BuildOutPath" -Recurse -Force
3838

39+
# Copy license
40+
Write-Verbose -Verbose -Message "Copying LICENSE file to '$BuildOutPath'"
41+
Copy-Item -Path "./LICENSE" -Dest "$BuildOutPath"
42+
43+
# Copy notice
44+
# Write-Verbose -Verbose -Message "Copying ThirdPartyNotices.txt to '$BuildOutPath'"
45+
# Copy-Item -Path "./ThirdPartyNotices.txt" -Dest "$BuildOutPath"
46+
3947
#
4048
# Copy DSC resources
4149
# TODO: This should not be part of PowerShellGet build/publish and should be moved to its own project
@@ -65,40 +73,21 @@ function DoBuild
6573
}
6674

6775
# Place build results
68-
if ($BuildFramework -eq "netstandard2.0") {
69-
$assemblyNames = @(
70-
'PowerShellGet'
71-
'Microsoft.Extensions.Logging.Abstractions'
72-
'MoreLinq'
73-
'NuGet.Commands'
74-
'NuGet.Common'
75-
'NuGet.Configuration'
76-
'NuGet.Frameworks'
77-
'NuGet.Packaging'
78-
'NuGet.ProjectModel'
79-
'NuGet.Protocol'
80-
'NuGet.Repositories'
81-
'NuGet.Versioning'
82-
'Newtonsoft.Json'
83-
)
84-
} elseif ($BuildFramework -eq 'net472') {
85-
$assemblyNames = @(
86-
'PowerShellGet'
87-
'Microsoft.Extensions.Logging.Abstractions'
88-
'MoreLinq'
89-
'NuGet.Commands'
90-
'NuGet.Common'
91-
'NuGet.Configuration'
92-
'NuGet.Frameworks'
93-
'NuGet.Packaging'
94-
'NuGet.ProjectModel'
95-
'NuGet.Protocol'
96-
'NuGet.Repositories'
97-
'NuGet.Versioning'
98-
'Newtonsoft.Json'
99-
'System.Security.Principal.Windows'
100-
)
101-
}
76+
$assemblyNames = @(
77+
'PowerShellGet'
78+
'Microsoft.Extensions.Logging.Abstractions'
79+
'MoreLinq'
80+
'NuGet.Commands'
81+
'NuGet.Common'
82+
'NuGet.Configuration'
83+
'NuGet.Frameworks'
84+
'NuGet.Packaging'
85+
'NuGet.ProjectModel'
86+
'NuGet.Protocol'
87+
'NuGet.Repositories'
88+
'NuGet.Versioning'
89+
'Newtonsoft.Json'
90+
)
10291

10392
$buildSuccess = $true
10493
foreach ($fileName in $assemblyNames)

src/PowerShellGet.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@{
55
RootModule = './netstandard2.0/PowerShellGet.dll'
6-
ModuleVersion = '3.0.11'
6+
ModuleVersion = '3.0.12'
77
GUID = '1d73a601-4a6c-43c5-ba3f-619b18bbb404'
88
Author = 'Microsoft Corporation'
99
CompanyName = 'Microsoft Corporation'

src/code/FindHelper.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
5+
using MoreLinq.Extensions;
6+
using NuGet.Common;
7+
using NuGet.Configuration;
8+
using NuGet.Protocol;
9+
using NuGet.Protocol.Core.Types;
10+
using NuGet.Versioning;
411
using System;
512
using System.Collections.Generic;
613
using System.Data;
7-
using Dbg = System.Diagnostics.Debug;
814
using System.Linq;
915
using System.Management.Automation;
1016
using System.Net;
1117
using System.Net.Http;
1218
using System.Threading;
13-
using MoreLinq.Extensions;
14-
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
15-
using static Microsoft.PowerShell.PowerShellGet.UtilClasses.PSResourceInfo;
16-
using NuGet.Common;
17-
using NuGet.Configuration;
18-
using NuGet.Protocol;
19-
using NuGet.Protocol.Core.Types;
20-
using NuGet.Versioning;
19+
20+
using Dbg = System.Diagnostics.Debug;
2121

2222
namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
2323
{
@@ -26,6 +26,8 @@ namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
2626
/// </summary>
2727
internal class FindHelper
2828
{
29+
#region Members
30+
2931
private CancellationToken _cancellationToken;
3032
private readonly PSCmdlet _cmdletPassedIn;
3133
private List<string> _pkgsLeftToFind;
@@ -50,12 +52,22 @@ internal class FindHelper
5052
private const int SearchAsyncMaxReturned = 5990;
5153
private const int GalleryMax = 12000;
5254

55+
#endregion
56+
57+
#region Constructor
58+
59+
private FindHelper() { }
60+
5361
public FindHelper(CancellationToken cancellationToken, PSCmdlet cmdletPassedIn)
5462
{
5563
_cancellationToken = cancellationToken;
5664
_cmdletPassedIn = cmdletPassedIn;
5765
}
5866

67+
#endregion
68+
69+
#region Public methods
70+
5971
public IEnumerable<PSResourceInfo> FindByResourceName(
6072
string[] name,
6173
ResourceType type,
@@ -175,7 +187,11 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
175187
}
176188
}
177189

178-
public IEnumerable<PSResourceInfo> SearchFromRepository(
190+
#endregion
191+
192+
#region Private methods
193+
194+
private IEnumerable<PSResourceInfo> SearchFromRepository(
179195
string repositoryName,
180196
Uri repositoryUrl)
181197
{
@@ -255,7 +271,7 @@ public IEnumerable<PSResourceInfo> SearchFromRepository(
255271
}
256272
}
257273

258-
public IEnumerable<PSResourceInfo> SearchAcrossNamesInRepository(
274+
private IEnumerable<PSResourceInfo> SearchAcrossNamesInRepository(
259275
string repositoryName,
260276
PackageSearchResource pkgSearchResource,
261277
PackageMetadataResource pkgMetadataResource,
@@ -637,5 +653,6 @@ SourceCacheContext sourceCacheContext
637653
}
638654
}
639655
}
656+
#endregion
640657
}
641-
}
658+
}

src/code/GetHelper.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
3+
4+
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
5+
using NuGet.Versioning;
36
using System;
47
using System.Collections.Generic;
5-
using Dbg = System.Diagnostics.Debug;
68
using System.IO;
7-
using System.Linq;
89
using System.Management.Automation;
9-
using System.Threading;
10-
using MoreLinq.Extensions;
11-
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
10+
11+
using Dbg = System.Diagnostics.Debug;
1212
using static Microsoft.PowerShell.PowerShellGet.UtilClasses.PSResourceInfo;
13-
using NuGet.Versioning;
1413

1514
namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
1615
{
@@ -38,7 +37,7 @@ public GetHelper(PSCmdlet cmdletPassedIn)
3837

3938
#region Public methods
4039

41-
public IEnumerable<PSResourceInfo> FilterPkgPaths(
40+
public IEnumerable<PSResourceInfo> GetPackagesFromPath(
4241
string[] name,
4342
VersionRange versionRange,
4443
List<string> pathsToSearch)

src/code/GetInstalledPSResource.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
5+
using NuGet.Versioning;
46
using System;
57
using System.Collections.Generic;
6-
using System.IO;
78
using System.Management.Automation;
8-
using System.Threading;
9-
using Microsoft.PowerShell.PowerShellGet.UtilClasses;
10-
using NuGet.Versioning;
119

1210
namespace Microsoft.PowerShell.PowerShellGet.Cmdlets
1311
{
@@ -130,7 +128,7 @@ protected override void ProcessRecord()
130128
}
131129

132130
GetHelper getHelper = new GetHelper(this);
133-
foreach (PSResourceInfo pkg in getHelper.FilterPkgPaths(namesToSearch, _versionRange, _pathsToSearch))
131+
foreach (PSResourceInfo pkg in getHelper.GetPackagesFromPath(namesToSearch, _versionRange, _pathsToSearch))
134132
{
135133
WriteObject(pkg);
136134
}

0 commit comments

Comments
 (0)