This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Register-PSRepository throws exception when run inside Windows Server container #106
Copy link
Copy link
Closed
Labels
Description
Problem Overview
We're trying to register an internal / private NuGet PowerShell module repository inside of a Windows Server Container. When we attempt to register the repository, an exception is thrown by the Register-PSRepository command. The repository can be registered properly outside of a Windows Server Container.
Steps to reproduce
- Create a
Dockerfilebased onmicrosoft/windowsservercore - Run
Register-PSRepositorycommand insideDockerfile
build.cmd
cd "%~dp0"
powershell.exe -Command Save-Module -Name PowerShellGet -Path ./
docker build --tag amazon/redacted --file Dockerfile --no-cache .
Dockerfile
FROM microsoft/windowsservercore
MAINTAINER Trevor Sullivan <tsulli@amazon.com>
RUN mkdir c:\Amazon
COPY [ "PackageManagement", "c:/Program Files/WindowsPowerShell/Modules/PackageManagement"]
COPY [ "PowerShellGet", "c:/Program Files/WindowsPowerShell/Modules/PowerShellGet"]
COPY redacted.ps1 c:\Amazon
RUN powershell.exe -ExecutionPolicy Bypass -File c:\Amazon\redacted.ps1
ENTRYPOINT powershell
Expected behavior
Container builds successfully, without errors.
Actual behavior
Exception is thrown:
Set-Variable : Object reference not set to an instance of an object.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.1.2.0\PSModule.psm1:4077
char:13
+ Set-Variable -Name selectedProviderName -value $null -Sco ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Set-Variable], NullReferenceE
xception
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShe
ll.Commands.SetVariableCommand
PackageManagement\Register-PackageSource : Unhandled Exception - Message:'One
or more errors occurred.' Name:'AggregateException' Stack Trace:' at
System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.GetResultCore(Boolean
waitCompletionNotification)
at Microsoft.PowerShell.PackageManagement.Cmdlets.RegisterPackageSource.Proc
essRecordAsync()
at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayCl
ass83_0.<AsyncRun>b__0()'
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.1.2.0\PSModule.psm1:4211
char:17
+ ... $null = PackageManagement\Register-PackageSource @PSBoundParamete ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Power...erPackageSo
urce:RegisterPackageSource) [Register-PackageSource], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageM
anagement.Cmdlets.RegisterPackageSource
redacted.ps1
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.3 -Force
$Parameters = @{
Name = 'customrepo'
SourceLocation = 'http://website.com/'
PublishLocation = 'http://website.com/api/v2/package'
InstallationPolicy = 'Trusted'
PackageManagementProvider = 'NuGet'
}
Register-PSRepository @Parameters
Environment data
Name Value
---- -----
PSVersion 5.1.14393.693
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.693
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1Cheers,
Trevor Sullivan
Reactions are currently unavailable