How to remove the References node from custom project type?

Hi All,

I have created a custom project type (based on the IronPython example) and I would like to stop the "References" project node from being created when a project is created (my project type does not use references). Would one of you be able to explain to me how this might be done?

Thanks in advance.

[544 byte] By [GrahamSibley] at [2008-1-7]
# 1

Hi Graham,

To remove 'References' node from your custom project you need to add following code to your ProjectNode iheritor:

Code Snippet

protected override ReferenceContainerNode CreateReferenceContainerNode()

{

return null;

}

Enjoy!
DmitryPavlov at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 2

Thanks a bunch Dmitry. That did the trick.

GrahamSibley at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 3
Thanks, I had the same problem.
elopio at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 4
Thanks this worked. How can i also remove the option in the context menu when you right click the project to add a reference?

Cheers

CBrookes86 at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 5

There is a logic how that commnad is shown now. Look at the base ProjectNode implementation of QueryStatusOnNode method. You will find here something like:

Code Snippet

case VsCommands2K.ADDREFERENCE:

result |= QueryStatusResult.SUPPORTED | QueryStatusResult.ENABLED;

return VSConstants.S_OK;

This code make the 'Add reference' command visible. Then have a look at ExecCommandOnNode method and you'll se following piece of code here:

Code Snippet

case VsCommands2K.ADDREFERENCE:

return this.AddProjectReference();

That code is calling the logic that shows the dialog and so on...

The mechanism described above is common for all similar menu commands. And you can use that to show / hide standard commands for your Solution Explorer nodes (project, folders, files, references and so on)...

Hope that helps!

DmitryPavlov at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 6
Thanks for your help, however i cant seem to get it to work.
Below is my code from my overridden QueryStatusOnNode

Code Snippet

if (guidCmdGroup == VsMenus.guidStandardCommandSet97)
{
switch ((VsCommands)cmd)
{
case VsCommands.AddExistingItem:
result |= QueryStatusResult.INVISIBLE;
return VSConstants.S_OK;

case VsCommands.AddNewItem:
result |= QueryStatusResult.INVISIBLE;
return VSConstants.S_OK;

case VsCommands.NewFolder:
result |= QueryStatusResult.INVISIBLE;
return VSConstants.S_OK;

case VsCommands.SetStartupProject:
result |= QueryStatusResult.INVISIBLE;
return VSConstants.S_OK;

}
}
else if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)
{

switch ((VsCommands2K)cmd)
{

case VsCommands2K.ADDREFERENCE:
result |= QueryStatusResult.NOTSUPPORTED | QueryStatusResult.INVISIBLE;
return VSConstants.S_OK;

}
}


The overrides to hide the commands from the VsCommands section (first switch statement) work fine and hide but the one for the VsCommands2K dont seem to be working.

I have included both the using lines:

Code Snippet

using VsCommands = Microsoft.VisualStudio.VSConstants.VSStd97CmdID;
using VsCommands2K = Microsoft.VisualStudio.VSConstants.VSStd2KCmdID;


What am I doing wrong?
CBrookes86 at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 7

You should do the same for two classes that have such menu item - ReferenceContainerNode and ProjectNode:

Code Snippet

protected override int QueryStatusOnNode(Guid guidCmdGroup, uint cmd, IntPtr pCmdText, ref QueryStatusResult result)

{

switch((VsCommands2K)cmd)

{

case VsCommands2K.ADDREFERENCE:

result |= QueryStatusResult.NOTSUPPORTED | QueryStatusResult.INVISIBLE;

return VSConstants.S_OK;

}

return base.QueryStatusOnNode(guidCmdGroup, cmd, pCmdText, ref result);

}

And for ProjectNode there is one more thing you should do:

Code Snippet

protected override QueryStatusResult QueryStatusCommandFromOleCommandTarget(Guid guidCmdGroup, uint cmd, out bool handled)

{

if (guidCmdGroup == VsMenus.guidStandardCommandSet2K)

{

switch((VsCommands2K)cmd)

{

case VsCommands2K.ADDREFERENCE:

handled = false; <-- NOTE THAT

return QueryStatusResult.NOTSUPPORTED | QueryStatusResult.INVISIBLE;

}

}

return base.QueryStatusCommandFromOleCommandTarget(guidCmdGroup, cmd, out handled);

}

I have tested it myself - that works. Enjoy!

DmitryPavlov at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 8
Thanks Dmitry, that worked perfectly.
Can you explain to me the second section of code you posted "QueryStatusCommandFromOleCommandTarget" - what is going on here.

Thanks

CBrookes86 at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...
# 9

Not sure I can. I did not dive into that yet (no need to do that yet ). So that is just a trick for now.

DmitryPavlov at 2007-10-2 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified