且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在visual studio中为解决方案动态创建解决方案文件夹?

更新时间:2022-03-12 02:39:36

要添加解决方案文件夹,您应该添加一个 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"