简体   繁体   English

解决方案中的Visual Studio 2017可扩展性项目计数

[英]Visual Studio 2017 Extensibility Project count in Solution

I am having two Visual Studio solutions lets say SolutionOne and SolutionTwo as follows: 我有两个Visual Studio解决方案,可以这样说SolutionOne和SolutionTwo:

SolutionOne 解决方案一

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{2408EC7B-2E06-46A5-B6AC-D4E985E30CBB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{DFF21B2A-7F52-448D-8867-D1C4EEAF73A7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Clients", "Clients", "{BABF1C97-CB5C-4AC5-81C6-6A81B0D45E27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api", "src\Api\Api.csproj", "{7059F655-BBD7-4CA3-9A76-2FF198996DA8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "src\Client\Client.csproj", "{B707F1AF-DD46-45D6-B4C5-BC2E9A3FB9B7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResourceOwnerClient", "src\ResourceOwnerClient\ResourceOwnerClient.csproj", "{40674C67-6A97-4B85-8154-92AEC74A37A0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcClient", "src\MvcClient\MvcClient.csproj", "{4CFB4883-9929-4814-BE22-2E19476CE4A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IdentityServerWithAspNetIdentity", "src\IdentityServerWithAspNetIdentity\IdentityServerWithAspNetIdentity.csproj", "{1ECB5581-FFA5-4C11-A491-C85ABD962033}"
EndProject

SolutionTwo 解决方案二

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApplication1", "WebApplication1\WebApplication1.csproj", "{C495AA01-06E7-47A1-B5A4-97352C689596}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{250ABB36-7C50-48BC-AEC7-7B0EA549C277}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{9C73E333-1C3D-4BB4-91B6-2C1C73BFB726}"
EndProject

**Note : "Global" section in both solutions removed for brevity. **注意:为简洁起见,两个解决方案中的“全局”部分均已删除。

I am trying to get project details from both solutions using following code. 我正在尝试使用以下代码从两个解决方案中获取项目详细信息。

    private void MenuItemCallback(object sender, EventArgs e)
    {
        var dte = Package.GetGlobalService(typeof(DTE)) as DTE2;
        Solution2 sln = dte.Solution as Solution2;

        string msg = string.Empty;
        foreach (Project prop in sln.Projects)
        {
            msg += prop.Name  +"\n";
        }
        MessageBox.Show(msg);
    }

Output of above code for 以上代码的输出

SolutionOne is: SolutionOne是:

  • src src
  • Solution Items 解决方案

SolutionTwo is : 解决方案二是:

  • WebApplication1 Web应用程序1
  • ClassLibrary1 ClassLibrary1
  • ConsoleApp1 ConsoleApp1

My question here is even though SolutionOne has 5 projects but instead of capturing all those 5 projects it gives just two solution folders in output. 我的问题是,即使SolutionOne有5个项目,但与其捕获所有这5个项目,不如在输出中提供两个解决方案文件夹。 Why is it so? 为什么会这样呢? Is it that it will just capture first level items? 难道它只会捕获第一级物品?

The project structure of a solution is recursive, not lineal, since there can be solution folders (that are modeled as EnvDTE.Project) which in turn contain other solution folders or projects. 解决方案的项目结构是递归的,而不是线性的,因为可以有解决方案文件夹(建模为EnvDTE.Project),而该文件夹又包含其他解决方案文件夹或项目。 See a sample of how to navigate it here: 在此处查看如何导航的示例:

HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in HOWTO:从Visual Studio .NET宏或加载项中导航解决方案的文件

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM