在 Visual Studio 中,我可以通过右键单击 -> 构建来构建按解决方案文件夹分组的多个项目。
是否有任何命令行/电源 shell 替代方案?
最佳答案
在上面的屏幕截图中,只需执行以下操作:
cd [directory with WindowsFormsApplication1.sln]
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
Powershell 只是“控制台”。要构建 sln 或 csproj,您需要 msbuild.exe这是用于构建 .NET 项目的工具
如果您只想从 sln 构建一个解决方案文件夹,这并不容易,因为 Visual Studio 中的文件夹是虚拟的,您需要解析 sln 文件才能找到文件夹
更新
以下代码将解析 sln 文件并为属于文件夹的项目运行 msbuild:
param([string]$slnPath=".\YourSLN.sln", [string]$VsFolderName="Your_folder")
$slnContent = Get-Content $slnPath
$folderLine = $slnContent | ?{$_.Contains("2150E333-8FDC-42A3-9474-1A3956D46DE8")} | ?{$_.Contains($VsFolderName)}
$guid = $folderLine.Split(", ")[-1].Replace('"',"")
#Write-host $guid
$csprojGuids = $slnContent | ?{$_.Contains("= "+$guid)} | %{$_.Split("=")[-2].Trim()}
#Write-Host $csprojGuids
for($i=0; $i -lt $csprojGuids.count; $i++){
$toFind = $csprojGuids[$i]
$def = $slnContent | ?{$_.Contains("Project")} | ?{$_.Contains($csprojGuids[$i])} | %{$_.Split(",")[-2].Trim().Replace('"','')}
Write-Host "building" $def
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe $def
}
关于.net - 如何从powershell构建VS解决方案文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27396501/