Creating a tree of Solution Folders using DTE and Package Manager Console

自闭症网瘾萝莉.ら 提交于 2019-12-08 04:35:47

问题


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

回答1:


I faced the same issue but I finally figured it out (it's working in my powershell script now). Apparently when finding a nested solution folder where property Kind has guid {66A26722-8FB5-11D2-AA7E-00C04F688DDE} it's not the correct object yet. You have to use the object within the found item.

It's not the most intuitive to call Object on an Object but in your example the following should not be null:

$f2interface = Get-Interface $f2.Object.Object ([EnvDte80.SolutionFolder])


来源:https://stackoverflow.com/questions/45056312/creating-a-tree-of-solution-folders-using-dte-and-package-manager-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!