将多个现有的.csproj添加到Visual Studio解决方案的简单方法?

编程入门 行业动态 更新时间:2024-10-27 06:27:30
本文介绍了将多个现有的.csproj添加到Visual Studio解决方案的简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经从源代码管理中签出了C#代码的一个分支.它可能在各个文件夹中包含50个项目.找不到现有的.sln文件.

I've checked out a branch of C# code from source control. It contains maybe 50 projects in various folders. There's no existing .sln file to be found.

我打算创建一个空白解决方案以添加现有解决方案. UI只允许我一次执行一个项目.

I intended to create a blank solution to add existing solutions. The UI only lets me do this one project at a time.

有什么我想念的吗?我想指定* .csproj文件的列表,并以某种方式提出一个包含所有项目的.sln文件.

Is there something I'm missing? I'd like to specify a list of *.csproj files and somehow come up with a .sln file that contains all the projects.

推荐答案

此处是Bertrand脚本的PowerShell版本,在解决方案文件旁边假定有Src和Test目录.

Here is a PowerShell version of Bertrand's script which assumes a Src and Test directory next to the solution file.

function GetGuidFromProject([string]$fileName) { $content = Get-Content $fileName $xml = [xml]$content $obj = $xml.Project.PropertyGroup.ProjectGuid return [Guid]$obj[0] } $slnPath = "C:\Project\Foo.sln" $solutionDirectory = [System.IO.Path]::GetDirectoryName($slnPath) $srcPath = [System.IO.Path]::GetDirectoryName($slnPath) $writer = new-object System.IO.StreamWriter ($slnPath, $false, [System.Text.Encoding]::UTF8) $writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 12.00") $writer.WriteLine("# Visual Studio 2013") $projects = gci $srcPath -Filter *.csproj -Recurse foreach ($project in $projects) { $fileName = [System.IO.Path]::GetFileNameWithoutExtension($project) $guid = GetGuidFromProject $project.FullName $slnRelativePath = $project.FullName.Replace($solutionDirectory, "").TrimStart("\") # Assume the project is a C# project {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} $writer.WriteLine("Project(""{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"") = ""$fileName"", ""$slnRelativePath"",""{$($guid.ToString().ToUpper())}""") $writer.WriteLine("EndProject") } $writer.Flush() $writer.Close() $writer.Dispose()

更多推荐

将多个现有的.csproj添加到Visual Studio解决方案的简单方法?

本文发布于:2023-11-01 23:35:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550732.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   解决方案   简单   方法   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!