使用DTE和Package Manager控制台创建解决方案文件夹树 [英] Creating a tree of Solution Folders using DTE and Package Manager Console
问题描述
我想使用Visual Studio软件包管理器控制台和powershell创建一个解决方案文件夹树,如下所示:
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')
通过执行以下操作,我可以获得对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]
显然是文件夹:
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
但是如果我将其强制转换为SolutionFolder,我将得到null:
But if I cast this to a SolutionFolder, I get null:
$f2interface = Get-Interface $f2.Object ([EnvDte80.SolutionFolder])
,现在$f2interface -eq $null
返回true.
值得注意的是,顶级文件夹和辅助解决方案文件夹的Kind属性是不同的:
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
推荐答案
我遇到了同样的问题,但是我终于弄清楚了(它现在正在我的Powershell脚本中运行).显然,当找到嵌套的解决方案文件夹时,属性Kind已引导为{66A26722-8FB5-11D2-AA7E-00C04F688DDE},它不是正确的对象.您必须在找到的项目中使用该对象.
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])
这篇关于使用DTE和Package Manager控制台创建解决方案文件夹树的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!