Add item as link on Custom project
I've just found that "add existing item as link" is not supported on the custom projects, at least using the source code of the sdk (just as it's done on the nested project sample).
Is it possible to modify the code to make that function work?
I've modified AddItemToHierarchy function, on HierarchyNode.cs, setting the uiFlags of the else statement as
Code Snippet
(uint)(__VSADDITEMFLAGS.VSADDITEM_AddExistingItems | __VSADDITEMFLAGS.VSADDITEM_ProjectHandlesLinks | __VSADDITEMFLAGS.VSADDITEM_AllowMultiSelect | __VSADDITEMFLAGS.VSADDITEM_AllowStickyFilter);
That makes the "Add as link" option appear.
Now I'm trying to modify the AddItemWithSpecific function, on ProjectNode.cs, but I'm a little confused and I'm not sure of what I'm doing.
If it's posible to modify the custom project as I want, I'll appreciate a lot if you tell me what other changes are required.
Thanks,
pura vida.
[1109 byte] By [
elopio] at [2008-1-7]
I've been looking deeper trying to understand how to make "add as link" work. It's hard to understand everything. Anyway, I've found something that has no sense on ProjectNode file (...\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Common\Source\CSharp\Project\ProjectNode.cs)
On the AddFileToMsBuild function, line 2891:
Code Snippet
if (this.IsCodeFile(itemPath))
but, that function is defined as
Code Snippet
public virtual bool IsCodeFile(string strFileName)
{
return false;
}
That's weird, why is it required to check if the item is a code file?
Thanks,
pura vida
Hi elopio,
I have not implemented 'Add as Link' feature myself but you are absolutely right - this feature is not implemented in VS SDK RTM 4.0. I think you should create special inheritor from FileNode MPF class and use it for linked files. You will need to control all places where MPF uses Url property for that file. Unfortunately, MPF has a lot of places where it make an assumption that file is located is under project root directory, so I am not absolutely sure that this feature can be implemented in principle without deep changing the MPF sources.
From my point of view you should post Suggestion on Microsoft connect website about adding that feature to VSSDK. Please drop here a link to your post to make us possible to vote this.
Regarding IsCodeFile method, you should override IsCodeFile in your custom ProjectNode inheritor depending your code files extension. That is the example of this method implementation:
public override bool IsCodeFile(string strFileName)
{
if (String.IsNullOrEmpty(strFileName))
{
return false;
}
return (String.Compare(Path.GetExtension(strFileName), "myCodeFileExt",
StringComparison.OrdinalIgnoreCase) == 0);
}
Hope that helps!