I am having two Visual Studio solutions lets say SolutionOne and SolutionTwo as follows:
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:
SolutionTwo is :
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. Why is it so? Is it that it will just capture first level items?
答案 0 :(得分:1)
解决方案的项目结构是递归的,而不是直线的,因为可以有解决方案文件夹(建模为EnvDTE.Project),后者又包含其他解决方案文件夹或项目。请参阅此处的导航示例示例:
HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in