locked
How to establish project item DependentUpon other item? RRS feed

  • Question

  • hello all,

    is there anyone can give a hand to tell me How to establish project item DependentUpon another item?like "form.cs" to "form.designer.cs" and so on.

    thanks a lot.

    Saturday, January 21, 2006 10:34 AM

Answers

  • Hi Jonathan,

    If you are trying to do it in a project template for an msbuild based project, this is done using the <DependentUpon>ParentNode_Include</DependentUpon> metadata to the file.

    To do it programatically, EnvDTE.ProjectItem.ProjectItems lets you add a file under an other. If the file is already part of the project, I am not sure what the best way to achieve that would be. There is an interface that let you set metadata but it would not update the UI immediately. It may be easiest to move it using cut&paste (select the source, send the cut command, select the parent, sent the paste command).

    Rusty

    Monday, April 17, 2006 7:15 AM

All replies

  • Within your own project type or within a project like C#? If it is witin a C# project, this is determined by partial classes and associations within the code.

    Craig

    Friday, January 27, 2006 7:29 PM
  •  Craig Skibo wrote:

    Within your own project type or within a project like C#? If it is witin a C# project, this is determined by partial classes and associations within the code.

    Craig

    That doesn't make sense to me.  If I have partial classes in two files, there isn't an entry in the project file saying that there is a dependency like there is with forms.

    The examples actually gloss over this by extending the XML designer rather than writing from scratch.

    How would one add two files per above from a wizard where there aren't necessarily any classes to start out with?  I kludged it, but I suspect it is not the best way (adding one, then moving the dependent item after it is added, which required having an open editor to get the right objects to construct the hierarchy with).

    Tuesday, January 31, 2006 3:15 PM
  • Hi Jonathan,

    If you are trying to do it in a project template for an msbuild based project, this is done using the <DependentUpon>ParentNode_Include</DependentUpon> metadata to the file.

    To do it programatically, EnvDTE.ProjectItem.ProjectItems lets you add a file under an other. If the file is already part of the project, I am not sure what the best way to achieve that would be. There is an interface that let you set metadata but it would not update the UI immediately. It may be easiest to move it using cut&paste (select the source, send the cut command, select the parent, sent the paste command).

    Rusty

    Monday, April 17, 2006 7:15 AM
  • thanks, Rusty

    i got it,it is helpful .

     

    matt

    Tuesday, April 18, 2006 1:24 AM
  • Since there might be others that would benefit from your solution...

     

    Do you mind posting a snippet that would let you add (or move) one project item under another?

     

    I have not had much luck at all.   So far I am basing my custom project on the Project Subtype example - not on PythonProject example... so I don't have a bunch of FileNode, DependentNode etc.   I can get a callback when the files are added .. but any attempt I have to call SetProperty() on the items seems to have no effect either graphically or with the .CSPROJ when it is saved.

     

    Thanks!

     

    R

    Thursday, May 10, 2007 6:12 PM
  • I think the right way to implement DependentOn behavior is to implement IVsEditorFactoryNotify Interface. And when

    NotifyItemAdded is called you add the Dependent FileNodes over the ProjectItem-Methods.

    Code Snippet

    private EnvDTE.ProjectItem GetProjectItemFromHierarchy(IVsHierarchy pHier, uint dwItemId)

    {

    object oObj;

    ErrorHandler.ThrowOnFailure(pHier.GetProperty(dwItemId, (int)__VSHPROPID.VSHPROPID_ExtObject, out oObj));

    EnvDTE.ProjectItem oItem = oObj as EnvDTE.ProjectItem;

    if (oItem == null)

    {

    Debug.Print("ArgumentException: Kein ProjectItem");

    throw new ArgumentException("Kein ProjectItem");

    }

    return oItem;

    } // func GetProjectItemFromHierarchy

     

    public int NotifyItemAdded(uint grfEFN, IVsHierarchy pHier, uint itemid, string pszMkDocument)

    {

      EnvDTE.ProjectItem oItem = GetProjectItemFromHierarchy(pHier, itemid);

      ..

      oItem.ProjectItems.AddFromFile(sGenName);

      ..

    }

     

    public int NotifyItemRenamed(IVsHierarchy pHier, uint itemid, string pszMkDocumentOld, string pszMkDocumentNew)

    {

      Here you have to rename the dependent nodes.

    }

     

     

     

    Wednesday, May 21, 2008 5:08 PM