简体   繁体   English

如何从PowerShell构建VS解决方案文件夹

[英]How to build VS solution folder from powershell

From Visual Studio I can build several projects grouped by solution folder by right click -> Build. 从Visual Studio我可以通过右键单击 - > Build来构建按解决方案文件夹分组的多个项目。

Solution folder build命令

Is there any command line / power shell alternative for that? 是否有替代命令行/电源shell?

In the screenshot above just do following: 在上面的截图中,请执行以下操作:

 cd [directory with WindowsFormsApplication1.sln]
 C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe

Powershell is just "console". Powershell只是“控制台”。 For building sln or csproj you need to msbuild.exe which is a tool for building .NET projects 要构建sln或csproj,您需要使用msbuild.exe ,这是一个用于构建.NET项目的工具

If you want only to build one solution folder from sln it is not so easy because folders in Visual Studio are virtual and you need to parse sln file to find folders 如果你只想从sln构建一个解决方案文件夹,那就不那么容易了,因为Visual Studio中的文件夹是虚拟的,你需要解析sln文件来查找文件夹

Update 更新

The following code will parse sln file and run msbuild for project which belongs to folder: 以下代码将解析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
}

You can use DTE to get paths of projects and then pass them to msbuild. 您可以使用DTE获取项目路径,然后将它们传递给msbuild。 Run this from Package Manager Console (presuming msbuild is in your %path%): 从包管理器控制台运行此命令(假设msbuild在您的%path%中):

project|% dte|% solution|? projectname -eq NewFolder1|% projectitems|% object|% {msbuild $_.fullname}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 要在 VS 解决方案中设置的文件夹属性/属性以将其及其下的文件包含在构建输出中 - Folder property/properties to set in VS solution to include it and files under it in build output 如何在VS解决方案中更改所有构建目录? - How do I change all the build directories in my VS solution? 使用MSBuild,如何从命令行构建MVC4解决方案(在此过程中应用Web.config转换)并输出到文件夹? - Using MSBuild, how do I build an MVC4 solution from the command line (applying Web.config transformations in the process) and output to a folder? 解决方案后,bin文件夹中有多个exe - multiple exe in bin folder after build solution 如何隐藏在解决方案资源管理器中显示的bin和obj文件夹 - How to hide bin and obj folder from being displayed in solution explorer 如何通过复制输出目录中的特定文件夹来配置Visual-Stuidio来构建我的解决方案? - How can I configure Visual-Stuidio to build my solution by copying a specific folder in the output directory? 如何从解决方案中的文件加载XML文件,并使用嵌入式资源进行构建? - How to load an XML file from a file in the solution, build with Embedded Resource? 如何使用来自Web服务的数据构建可伸缩的报告解决方案? - How to build a scalable Reporting Solution with data from a web service? MSBuild项目与PowerShell构建过程 - MSBuild project vs PowerShell build procedure 如何使用批处理文件构建解决方案 - How to build solution using batchfile
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM