如何在visual studio中为解决方案动态创建解决方案文件夹? [英] How to create a solution folder for a solution in visual studio dynamically?
问题描述
我想使用 PowerShell 脚本在 Visual Studio 中动态创建一个新的解决方案文件夹.
I want to create a new Solution Folder dynamically in Visual Studio using PowerShell script.
我知道如何在 Visual Studio 中手动为现有解决方案创建解决方案文件夹,但有没有办法使用 PowerShell 使其自动化?
I know how to create a solution folder for an existing solution in Visual Studio manually but is there a way we can automate it using PowerShell?
推荐答案
要添加解决方案文件夹,您应该添加一个 Project
条目.解决方案文件夹的项目类型的 Guid 应为:"{2150E333-8FDC-42A3-9474-1A3956D46DE8}"
,对于项目 Guid,您应该使用新指南.
To add a Solution Folder, you should add a Project
entry. The Guid for the Project Type for a solution folder should be : "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"
and for the project Guid, you should use a new Guid.
这是一个将文件夹添加到解决方案文件的函数:
Here is a function which adds a folder to a solution file:
Function AddFolderToSolution($folderName, $solutionFile)
{
$solutionFolderGuid = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}"
$content = [System.IO.File]::ReadLines($solutionFile)
$lines = New-Object System.Collections.Generic.List[string]
$lines.AddRange($content)
$index = $lines.IndexOf("Global")
$guid = [System.Guid]::NewGuid().ToString().ToUpper()
$txt = "Project(`"$solutionFolderGuid`") = `"$folderName`", `"$folderName`", `"$guid`""
$lines.Insert($index, $txt)
$lines.Insert($index+1, "EndProject")
[System.IO.File]::WriteAllLines($solutionFile, $lines)
}
这是用法:
AddFolderToSolution "NewFolder10" "D:\Solution1.sln"
这篇关于如何在visual studio中为解决方案动态创建解决方案文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!