I would like to create a tree of solution folders using Visual Studio Package Manager Console and powershell, like this:
Solution
+--- F1
+--- F2
+--- F3
I can create the first folder using this command:
PM> $dte.Solution.AddSolutionFolder('F1')
And I can create the second folder using these commands:
PM> $f1 = $dte.Solution.ProjectItems.Item(2)
PM> $f1interface = get-interface $f1.Object ([EnvDTE80.SolutionFolder])
PM> $f1interface.AddSolutionFolder('F2')
And I can get a reference to F2 (I could have also saved the returned value from the line above), by doing this:
PM> $f2 = $f1.ProjectItems[0]
Which clearly is the folder:
PM> $f2
IsDirty : False
FileCount : 1
Name : F2
Collection : System.__ComObject
Properties :
DTE : System.__ComObject
Kind : {66A26722-8FB5-11D2-AA7E-00C04F688DDE}
ProjectItems :
Object : System.__ComObject
ExtenderNames : {}
ExtenderCATID : {610d4613-d0d5-11d2-8599-006097c68e81}
Saved : False
ConfigurationManager :
FileCodeModel :
Document :
SubProject : System.__ComObject
ContainingProject : System.__ComObject
But if I cast this to a SolutionFolder, I get null:
$f2interface = Get-Interface $f2.Object ([EnvDte80.SolutionFolder])
and now $f2interface -eq $null
returns true.
It's worth noting that the Kind property of a top level and secondary solution folder are different:
PM> $f1.Kind
{66A26720-8FB5-11D2-AA7E-00C04F688DDE}
PM> $f2.Kind
{66A26721-8FB5-11D2-AA7E-00C04F688DDE}
I consulted these sources:
- http://blog.marcduiker.nl/2016/12/29/hands-on-with-sitecore-helix-anatomy-add-helix-powershell-script.html
- https://msdn.microsoft.com/en-us/library/envdte80.solutionfolder.aspx