我正在尝试使用 Powershell 在 Windows Server 2019 实例上自动安装 VS Studio 2019 构建工具。假设构建工具引导程序与常规引导程序共享相同的命令行界面,我想通过 --add 安装 2 个工作负载及其推荐的组件。MS 文档指定;includeRecommended
WorkloadID 的后缀。由于 powershell 中的 ;,命令标志的正确识别似乎失败。我如何告诉引导程序包含工作负载的推荐组件?
输出:
PS C:\Users\Administrator> Invoke-WebRequest https://s3.eu-central-1.amazonaws.com/.../vs_buildtools
__1986933399.1585486755.exe -OutFile c:\vs.exe
PS C:\Users\Administrator> c:\vs.exe --passive --wait `
>> --add Microsoft.VisualStudio.Workload.MSBuildTools;includeRecommended `
>> --add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
>> --add Microsoft.Component.MSBuild `
>>
includeRecommended : The term 'includeRecommended' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:2 char:52
+ ... add Microsoft.VisualStudio.Workload.MSBuildTools;includeRecommended `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (includeRecommended:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
includeRecommended : The term 'includeRecommended' is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.
At line:3 char:47
+ --add Microsoft.VisualStudio.Workload.VCTools;includeRecommended `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (includeRecommended:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
includeRecommended flag for WorkloadId installment not reconized
答案1
将参数值放在引号内。
c:\vs.exe --passive --wait `
--add "Microsoft.VisualStudio.Workload.MSBuildTools;includeRecommended" `
--add "Microsoft.VisualStudio.Workload.VCTools;includeRecommended" `
--add Microsoft.Component.MSBuild `
在 Powershell 中,您可以通过用 分隔多个命令,在一行中运行多个命令;
。因此,Powershell 认为命令以 结尾;
,并搜索具有下一个名称的 cmdlet。
或者,逃避他们也应该有效:
--add Microsoft.VisualStudio.Workload.MSBuildTools`;includeRecommended `