.net - 如何从powershell构建VS解决方案文件夹

标签 .net visual-studio powershell command-line build-automation

在 Visual Studio 中,我可以通过右键单击 -> 构建来构建按解决方案文件夹分组的多个项目。

Solution folder build command

是否有任何命令行/电源 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/

相关文章:

c# - 解决方案不在 Visual Studio 中运行/构建/重建

c - 使用 Visual Studio 2013 链接 C 语言的 lib 库

windows - 哪里可以下载windows xp平台的SDK?

powershell - Powershell:生产中的调试/良好异常处理

powershell - 使用 PowerShell 从 Google Drive 下载文件

c# - 在 Winform 中访问用户控件的控件属性的正确方法是什么?

c# - 如何将字符串从 native 代码返回到 Windows Azure 中的托管代码?

powershell - 从PowerShell执行SQL * Plus

c# - 通过 C# 确定本地组的成员

c# - : myType. GetType() 和 typeof(MyType) 哪个更有效?