【发布时间】:2021-09-11 17:07:16
【问题描述】:
我从下面的 C# 方法调用 powershell cmdlet,它在 Install-Module Name CosmosDb 行失败,并出现以下错误
“使用“2”个参数调用“ShouldContinue”的异常:“一个命令 提示用户失败,因为主机程序或命令 type 不支持用户交互。主机试图 使用以下消息请求确认:PowerShellGet 需要 NuGet 提供程序版本“2.8.5.201”或更高版本才能与之交互 基于 NuGet 的存储库。 NuGet 提供程序必须在 'C:\Program Files\PackageManagement\ProviderAssemblies' 或 'C:\Users\UserName\AppData\Local\PackageManagement\ProviderAssemblies'。 您还可以通过运行安装 NuGet 提供程序 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -力量'。是否希望 PowerShellGet 现在安装和导入 NuGet 提供程序?"
C#代码:
{
InitialSessionState initialSessionState = InitialSessionState.CreateDefault();
initialSessionState.ExecutionPolicy = ExecutionPolicy.Unrestricted;
using Runspace runspace = RunspaceFactory.CreateRunspace( initialSessionState );
string path = Path.Combine( CosmosDataFixture.Root , @"TestData\GetrRecording.ps1" );
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript( path );
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
}
我的 ps1 脚本文件中的 Powershell cmdlet
ECHO 'Y'|Import-Module "$env:ProgramFiles\Azure Cosmos DB Emulator\PSModules\Microsoft.Azure.CosmosDB.Emulator"
Install-Module PowershellGet -Force -Scope CurrentUser
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.208 -Force
Install-Module -Name CosmosDB -Scope CurrentUser -Force
我需要第一行和最后一行,但错误提示我在 middl 中添加这两个
【问题讨论】:
标签: c# powershell nuget