Visual Studio 如何在powershell上运行vswhere

at0kjp5o  于 2022-12-19  发布在  Shell
关注(0)|答案(2)|浏览(139)

我找到这个脚本来查找msbuild.exe的位置,但是它不起作用。当我运行它时,它说“无法找到与参数名称'latest'匹配的参数”https://github.com/microsoft/vswhere/wiki/Find-MSBuild
下面是我的脚本:

$path = %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe | select-object -first 1
if ($path) {
  & $path $args
}

有人知道我做错了什么吗?我试着用引号把路径封装起来,然后把它放到一个变量里,试着用Invoke-Expression,但是也不起作用。在bash中,我所需要做的就是用'封装命令,它就可以起作用了。

Invoke-Expression -Command "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe"
x86: The term 'x86' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

这也不行

55ooxyrt

55ooxyrt1#

试试这个,这里我显式地创建了一个独立字符串的参数列表。

$path = "$(${env:CommonProgramFiles(x86)})\Microsoft Visual Studio\Installer\vswhere.exe" 
$args = "-latest", "-requires Microsoft.Component.MSBuild", "-find MSBuild\**\Bin\MSBuild.exe"

if ($path) {
  Start-Process $path -ArgumentList $args
}

我无法测试,因为我没有Visual Studio。

nxowjjhe

nxowjjhe2#

这是我写的“小”字。
它将:
1.将最新推荐的Nuget.exe下载到保存此PS脚本的同一目录中。
1.下载/安装“vswhere”nuget(在脚本目录中)
1.将找到最新的“MSBuild.exe”路径
第一个月
输出:
Feeds used: https://api.nuget.org/v3/index.json C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\ Installing package 'vswhere' to 'G:\scripts\ps'. CACHE https://api.nuget.org/v3/registration5-gz-semver2/vswhere/index.json Attempting to gather dependency information for package 'vswhere.3.1.1' with respect to project 'G:\scripts\ps', targeting 'Any, Version= v0.0' Gathering dependency information took 15 ms Attempting to resolve dependencies for package 'vswhere.3.1.1' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'vswhere.3.1.1' Resolved actions to install package 'vswhere.3.1.1' Retrieving package 'vswhere 3.1.1' from 'nuget.org'. Adding package 'vswhere.3.1.1' to folder 'G:\scripts\ps' WARNING: Install failed. Rolling back... Executing nuget actions took 483 ms nuget.exe : The requested operation cannot be performed on a file with a user-mapped section open. At G:\scripts\ps\Get-MsBuildDir.ps1:21 char:9 + &"$nuget" $args + ~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (The requested o...d section open.:String) [], RemoteException + FullyQualifiedErrorId : NativeCommandError Nuget was successfully downloaded. vswhere executable: "G:\scripts\ps\vswhere\tools\vswhere.exe" MSBuild exeutable: "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe"

相关问题