如何在VS解决方案文件中获取项目列表? [C#] [英] How to get a list of projects in VS solution file? [C#]

查看:252
本文介绍了如何在VS解决方案文件中获取项目列表? [C#]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在寻找一种读取VS sln文件的好方法,并从该文件中获取项目列表.

我正在尝试读取所有行,并通过识别项目行w方法startStart(string)来获取项目名称和路径.

sln文件中的示例行:

Hi,

I''m looking for a good way to read VS sln file, and get the list of projects from this file.

I''m trying to read all lines, and get the project name and path by recognizing project line w method: startWith(string).

Example line from sln file:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsFormsApplication2", "WindowsFormsApplication2\WindowsFormsApplication2.csproj", "{5E1AD1FF-FE84-46A2-94D5-71BAAC929B7F}"



如您所见,路径不完整,因此在根文件夹中搜索此文件以获取项目文件的完整路径需要花费大量时间.

有时,如果项目位于上层目录中,则路径看起来像:"\ .. \ WindowsFormsApplication2 \ WindowsFormsApplication2.csproj"

如何获得这些项目和字符串Aray或哈希表的路径?也许使用EnvDTE,EnvDTE80或Microsoft.VisualStudio有什么用?



As you can see, the path is not full, searching for this file in root folder to get full path of project file takes to much time.

Sometimes if project is loceted in upper directory the path looks like: "\..\WindowsFormsApplication2\WindowsFormsApplication2.csproj"

How to get these projects and paths to string aray or hashtable? Maybe something with using EnvDTE, EnvDTE80 or Microsoft.VisualStudio?

推荐答案

对我来说,就像您可以使用正则表达式获取值一样.我假设这些路径相对于sln文件的位置.
Looks to me like you could use a regex to get the values. I assume that the paths are relative to the location of the sln file.


您能帮我如何将这行更改为regex并获取这些值吗?
Could you help me how to change this line to regex, and get these values?


这篇关于如何在VS解决方案文件中获取项目列表? [C#]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆