Skip to content

Commit 1d5a50f

Browse files
committed
Update bootstrap instructions
1 parent 03aec20 commit 1d5a50f

File tree

1 file changed

+58
-156
lines changed

1 file changed

+58
-156
lines changed
Lines changed: 58 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,46 @@
11
---
2-
description: This article explains how to install the NuGet components required to support working with the PowerShell Gallery.
3-
ms.date: 11/16/2022
2+
description: This article explains how to install the required NuGet components for Windows PowerShell 5.1.
3+
ms.date: 01/27/2025
44
title: Bootstrapping NuGet
55
---
6-
# Bootstrap the NuGet provider and NuGet.exe
6+
# Bootstrap the NuGet components for Windows PowerShell 5.1
77

8-
NuGet.exe is not included in the latest NuGet provider. For publish operations of either a module
9-
or script, PowerShellGet requires the binary executable **NuGet.exe**. Only the NuGet provider is
10-
required for all other operations, including **find**, **install**, **save**, and **uninstall**.
11-
PowerShellGet includes logic to handle either a combined bootstrap of the NuGet provider and
12-
NuGet.exe, or bootstrap of only the NuGet provider. In either case, only a single prompt message
13-
should occur. If the machine is not connected to the Internet, the user or an administrator must
14-
copy a trusted instance of the NuGet provider and/or the NuGet.exe file to the disconnected
15-
machine.
8+
On a new deployment of Windows, Windows PowerShell 5.1 doesn't include to the necessary NuGet
9+
components to interact with the PowerShell Gallery. PowerShellGet includes logic to update these
10+
components as long as you can connect to the PowerShell Gallery. If the machine isn't connected to
11+
the internet, you must copy required files from a trusted source to the disconnected machine.
1612

17-
> [!NOTE]
18-
> Starting with version 6, the NuGet provider is included in the installation of PowerShell.
13+
The required NuGet components are included in PowerShellGet v2+ and PackageManagement v1.1+. Newer
14+
versions of these modules are available from the PowerShell Gallery and included in PowerShell 6 and
15+
higher. These instructions are for Windows PowerShell 5.1.
1916

20-
## Resolving error when the NuGet provider has not been installed on a machine that is Internet connected
17+
> [!IMPORTANT]
18+
> After bootstrapping the NuGet components, you must install latest versions of the PowerShellGet
19+
> and PackageManagement modules to be supported.
2120
22-
```powershell
23-
Find-Module -Repository PSGallery -Verbose -Name Contoso
24-
```
21+
## Bootstrap on an internet-connected machine
2522

26-
```Output
27-
NuGet provider is required to continue
28-
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based
29-
repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
30-
'C:\Users\user1\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet
31-
provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you
32-
want PowerShellGet to install and import the NuGet provider now?
33-
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): n
34-
Find-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure
35-
that '2.8.5.201' or newer version of NuGet provider is installed.
36-
At line:1 char:1
37-
+ Find-Module -Repository PSGallery -Verbose -Name Contoso
38-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39-
+ CategoryInfo : InvalidOperation: (:) [Find-Module], InvalidOperationException
40-
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Find-Module
41-
```
23+
The following processes assume the machine is connected to the internet and can download files from
24+
a public location.
25+
26+
### ERROR: NuGet provider is required to continue
27+
28+
You receive this error when the NuGet provider isn't available on the machine.
4229

4330
```powershell
4431
Find-Module -Repository PSGallery -Verbose -Name Contoso
4532
```
4633

34+
Answer the prompt with `Y` to install the NuGet provider.
35+
4736
```Output
4837
NuGet provider is required to continue
49-
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based
50-
repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
51-
'C:\Users\user1\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet
52-
provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you
53-
want PowerShellGet to install and import the NuGet provider now?
38+
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet
39+
-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageMan
40+
agement\ProviderAssemblies' or 'C:\Users\user1\AppData\Local\PackageManagement\ProviderAs
41+
semblies'. You can also install the NuGet provider by running 'Install-PackageProvider -N
42+
ame NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and imp
43+
ort the NuGet provider now?
5444
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
5545
VERBOSE: Installing NuGet provider.
5646
@@ -59,154 +49,66 @@ Version Name Type Repository D
5949
2.5 Contoso Module PSGallery Contoso module
6050
```
6151

62-
## Resolving error when the NuGet provider is available and NuGet.exe is not available during the publish operation on a machine that is Internet connected
63-
64-
```powershell
65-
Publish-Module -Name Contoso -Repository PSGallery -Verbose
66-
```
52+
### ERROR: NuGet.exe is required to continue
6753

68-
```Output
69-
NuGet.exe is required to continue
70-
PowerShellGet requires NuGet.exe to publish an item to the NuGet-based repositories. NuGet.exe must
71-
be available under one of the paths specified in PATH environment variable value. Do you want
72-
PowerShellGet to install NuGet.exe now?
73-
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): N
74-
Publish-Module : NuGet.exe is required to interact with NuGet-based repositories. Please ensure
75-
that NuGet.exe is available under one of the paths specified in PATH environment variable value.
76-
At line:1 char:1
77-
+ Publish-Module -Name Contoso -Repository PSGallery -Verbose
78-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
79-
+ CategoryInfo : InvalidOperation: (:) [Publish-Module], InvalidOperationException
80-
+ FullyQualifiedErrorId : CouldNotInstallNuGetExe,Publish-Module
81-
```
54+
You receive this error when the NuGet provider is available, but the `nuget.exe` binary isn't.
8255

8356
```powershell
8457
Publish-Module -Name Contoso -Repository PSGallery -Verbose
8558
```
8659

60+
Answer the prompt with `Y` to install `nuget.exe`.
61+
8762
```Output
8863
NuGet.exe is required to continue
89-
PowerShellGet requires NuGet.exe to publish an item to the NuGet-based repositories. NuGet.exe must
90-
be available under one of the paths specified in PATH environment variable value. Do you want
91-
PowerShellGet to install NuGet.exe now?
64+
PowerShellGet requires NuGet.exe to publish an item to the NuGet-based repositories. NuGe
65+
t.exe must be available under one of the paths specified in PATH environment variable val
66+
ue. Do you want PowerShellGet to install NuGet.exe now?
9267
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
9368
VERBOSE: Installing NuGet.exe.
94-
VERBOSE: Successfully published module 'Contoso' to the module publish location 'https://www.powershellgallery.com/api/v2/'.
69+
VERBOSE: Successfully published module 'Contoso' to the module publish location 'https://
70+
www.powershellgallery.com/api/v2/'.
9571
Please allow few minutes for 'Contoso' to show up in the search results.
9672
```
9773

98-
## Resolving error when both NuGet provider and NuGet.exe are not available during the publish operation on a machine that is Internet connected
74+
### ERROR: NuGet.exe and NuGet provider are required to continue
9975

100-
```powershell
101-
Publish-Module -Name Contoso -Repository PSGallery -Verbose
102-
```
103-
104-
```Output
105-
NuGet.exe and NuGet provider are required to continue
106-
PowerShellGet requires NuGet.exe and NuGet provider version '2.8.5.201' or newer to interact with
107-
the NuGet-based repositories. Do you want PowerShellGet to install both NuGet.exe and NuGet provider
108-
now?
109-
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): N
110-
Publish-Module : PowerShellGet requires NuGet.exe and NuGet provider version '2.8.5.201' or newer
111-
to interact with the NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of
112-
NuGet provider is installed and NuGet.exe is available under one of the paths specified in PATH
113-
environment variable value.
114-
At line:1 char:1
115-
+ Publish-Module -Name Contoso -Repository PSGallery -Verbose
116-
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
117-
+ CategoryInfo : InvalidOperation: (:) [Publish-Module], InvalidOperationException
118-
+ FullyQualifiedErrorId : CouldNotInstallNuGetBinaries,Publish-Module
119-
```
76+
You receive this error when both the NuGet provider and `nuget.exe` aren't installed.
12077

12178
```powershell
12279
Publish-Module -Name Contoso -Repository PSGallery -Verbose
12380
```
12481

82+
Answer the prompt with `Y` to install both the NuGet provider and `nuget.exe`.
83+
12584
```Output
12685
NuGet.exe and NuGet provider are required to continue
127-
PowerShellGet requires NuGet.exe and NuGet provider version '2.8.5.201' or newer to interact with
128-
the NuGet-based repositories. Do you want PowerShellGet to install both NuGet.exe and NuGet provider
129-
now?
86+
PowerShellGet requires NuGet.exe and NuGet provider version '2.8.5.201' or newer to inter
87+
act with the NuGet-based repositories. Do you want PowerShellGet to install both NuGet.ex
88+
e and NuGet provider now?
13089
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
13190
VERBOSE: Installing NuGet provider.
13291
VERBOSE: Installing NuGet.exe.
133-
VERBOSE: Successfully published module 'Contoso' to the module publish location 'https://www.powershellgallery.com/api/v2/'.
92+
VERBOSE: Successfully published module 'Contoso' to the module publish location 'https://
93+
www.powershellgallery.com/api/v2/'.
13494
Please allow few minutes for 'Contoso' to show up in the search results.
13595
```
13696

137-
## Manually bootstrapping the NuGet provider on a machine that is not connected to the Internet
138-
139-
The processes demonstrated above assume the machine is connected to the Internet and can download
140-
files from a public location. If that is not possible, the only option is to bootstrap a machine
141-
using the processes given above, and manually copy the provider to the isolated node through an
142-
offline trusted process. The most common use case for this scenario is when a private gallery is
143-
available to support an isolated environment.
144-
145-
After following the process above to bootstrap an Internet connected machine, you will find
146-
provider files in the location:
147-
148-
`C:\Program Files\PackageManagement\ProviderAssemblies\`
149-
150-
The folder/file structure of the NuGet provider will be (possibly with a different version number):
151-
152-
```
153-
NuGet
154-
--2.8.5.208
155-
----Microsoft.PackageManagement.NuGetProvider.dll
156-
```
157-
158-
Copy these folders and file using a trusted process to the offline machines. To use the provider on
159-
the offline machine, it must be imported. Run the following command on the offline machine:
160-
161-
```powershell
162-
Import-PackageProvider -Name NuGet
163-
```
164-
165-
## Manually bootstrapping NuGet.exe to support publish operations on a machine that is not connected to the Internet
166-
167-
In addition to the process to manually bootstrap the NuGet provider, if the machine will be used to
168-
publish modules or scripts to a private gallery using the `Publish-Module` or `Publish-Script`
169-
cmdlets, the NuGet.exe binary executable file will be required.
170-
171-
The most common use case for this scenario is when a private gallery is available to support an
172-
isolated environment. There are two options to obtain the NuGet.exe file.
173-
174-
One option is to bootstrap a machine that is Internet connected and copy the files to the offline
175-
machines using a trusted process. After bootstrapping the Internet connected machine, the NuGet.exe
176-
binary will be located in one of two folders:
177-
178-
- If the `Publish-Module` or `Publish-Script` cmdlets were executed with elevated permissions (As
179-
an Administrator):
180-
181-
```powershell
182-
$env:ProgramData\Microsoft\Windows\PowerShell\PowerShellGet
183-
```
184-
185-
- If the cmdlets were executed as a user without elevated permissions:
186-
187-
```powershell
188-
$HOME\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\
189-
```
97+
## Bootstrap on a machine not connected to the internet
19098

191-
A second option is to download NuGet.exe from the NuGet.Org website:
192-
[https://dist.nuget.org/index.html](https://www.nuget.org/downloads) When selecting a NugGet
193-
version for production machines, make sure it is later than 2.8.5.208, and identify the version
194-
that has been labeled "recommended". Remember to unblock the file if it was downloaded using a
195-
browser. This can be performed by using the `Unblock-File` cmdlet.
99+
The following processes assume the machine isn't connected to the internet. To install the necessary
100+
components, follow the bootstrap process on an internet-connected machine then manually copy the
101+
provider to the isolated node through an offline trusted process.
196102

197-
In either case, the NuGet.exe file can be copied to any location in `$env:PATH`, but the standard
198-
locations are:
103+
1. Copy the NuGet provider files to the offline machine.
199104

200-
- To make the executable available so that all users can use `Publish-Module` and `Publish-Script`
201-
cmdlets:
105+
Copy the `C:\Program Files\PackageManagement\ProviderAssemblies\NuGet` folder from the connected
106+
machine to the same location on the offline machine.
202107

203-
```powershell
204-
$env:ProgramData\Microsoft\Windows\PowerShell\PowerShellGet
205-
```
108+
1. Copy the PowerShellGet and PackageManagement modules to the offline machine.
206109

207-
- To make the executable available to only a specific user, copy to the location within only that
208-
user's profile:
110+
Copy the following module folders from the connected machine to same location on the offline
111+
machine.
209112

210-
```powershell
211-
$HOME\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\
212-
```
113+
- `C:\Program Files\WindowsPowerShell\Modules\PowerShellGet`
114+
- `C:\Program Files\WindowsPowerShell\Modules\PackageManagement`

0 commit comments

Comments
 (0)