C# 解决方案文件夹的依赖关系
我创建了一些VisualStudio扩展,并以编程方式创建了解决方案文件夹。 但我不知道如何从另一个解决方案文件夹创建一个依赖项? 有人能帮我解决这个问题吗?谢谢C# 解决方案文件夹的依赖关系,c#,visual-studio-2010,directory,solution,vsx,C#,Visual Studio 2010,Directory,Solution,Vsx,我创建了一些VisualStudio扩展,并以编程方式创建了解决方案文件夹。 但我不知道如何从另一个解决方案文件夹创建一个依赖项? 有人能帮我解决这个问题吗?谢谢 |--- SolutionFolder | |--- SolutionFolder | |--- SolutionFolder |--- SolutionFolder 这是我的密码: (object sender, EventArgs args) => { Guid slnFldrG
|--- SolutionFolder
| |--- SolutionFolder
| |--- SolutionFolder
|--- SolutionFolder
这是我的密码:
(object sender, EventArgs args) =>
{
Guid slnFldrGuid = new Guid("2150E333-8FDC-42A3-9474-1A3956D46DE8");
Guid iidProject = typeof(IVsHierarchy).GUID;
IVsSolution solution = GetService<IVsSolution, SVsSolution>();
IVsHierarchy parent = UIShellUtilities.GetSelectedHierarchy();
IVsHierarchy nested = null;
IntPtr project = IntPtr.Zero;
int canceled = 0;
if ((null != solution) && (null != parent))
{
IVsProjectFactory factory = null;
ErrorHandler.ThrowOnFailure(solution.GetProjectFactory(
0, new Guid[] { slnFldrGuid }, null, out factory));
try
{
ErrorHandler.ThrowOnFailure(factory.CreateProject(
null, null, "New My Folder", 0, ref iidProject, out project, out canceled));
if (project != IntPtr.Zero)
{
nested = Marshal.GetTypedObjectForIUnknown(project, typeof(IVsHierarchy)) as IVsHierarchy;
Debug.Assert(nested != null, "Nested hierarchy could not be created");
Debug.Assert(canceled == 0);
}
} finally
{
if (project != IntPtr.Zero)
Marshal.Release(project);
}
uint itemid = VSConstants.VSITEMID_ROOT;
// Link into the nested VS hierarchy.
//ErrorHandler.ThrowOnFailure(nested.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchy, parent));
//ErrorHandler.ThrowOnFailure(nested.SetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ParentHierarchyItemid, (object)itemid));
}
}
(对象发送方,事件args args)=>
{
Guid slnFldrGuid=新Guid(“2150E333-8FDC-42A3-9474-1A3956D46DE8”);
Guid iidProject=typeof(IVsHierarchy).Guid;
IVS解决方案=GetService();
IVsHierarchy parent=UIShellUtilities.GetSelectedHierarchy();
IVsHierarchy嵌套=空;
IntPtr项目=IntPtr.Zero;
int=0;
if((null!=解决方案)&&(null!=父项))
{
IVsProjectFactory工厂=空;
ErrorHandler.ThrowOnFailure(solution.GetProjectFactory(
0,新Guid[]{slnFldrGuid},null,出厂时];
尝试
{
ErrorHandler.ThrowOnFailure(factory.CreateProject(
null,null,“新建我的文件夹”,0,引用iidProject,out project,out cancelled);
如果(项目!=IntPtr.Zero)
{
嵌套=Marshal.GetTypedObjectForIUnknown(project,typeof(IVsHierarchy))作为IVsHierarchy;
Assert(嵌套!=null,“无法创建嵌套层次结构”);
Assert(已取消==0);
}
}最后
{
如果(项目!=IntPtr.Zero)
元帅发布(项目);
}
uint itemid=VSConstants.VSITEMID_根;
//链接到嵌套的VS层次结构。
//ErrorHandler.ThrowOnFailure(nested.SetProperty(VSConstants.VSITEMID_ROOT,(int)_VSHPROPID.VSHPROPID_ParentHierarchy,parent));
//ErrorHandler.ThrowOnFailure(嵌套的.SetProperty(VSConstants.VSITEMID_根,(int)_VSHPROPID.VSHPROPID_ParentHierarchyItemid,(对象)itemid));
}
}
使用自动化模型EnvDTE创建嵌套的解决方案文件夹要容易得多,它也可以从包中使用
见:
如何在另一个解决方案文件夹中创建解决方案文件夹