From VSFeedback
AddFromTemplate/AddFromFile/AddFromFileCopy does not nest items if called on the ProjectItems of a file.
A solution for reproducing the scenario can found here: https://github.com/renegadexx/Vs2017AutomationTests
Any news on this.
@srivatsn Any progress on this?
This is dangling around for 2.5 years now! Since more and more people migrate to the new project format, this is starting to have real impact. (see e.g. https://github.com/tom-englert/ResXResourceManager/issues/240)
@jjmew This is no longer assigned to any milestone, will this never be fixed?
@tom-englert it just means that we haven't yet decided on a timeline to fix it in dev 16.
You can nest items by setting the DependentUpon properties of the project item. Here I demonstrate how to do that.
I've tested the .NET Standard sample provided in the question (https://github.com/renegadexx/Vs2017AutomationTests) and it appears to work. I needed to change the call to GetService to GetCOMService in VsAutomationHelper.CS.ttinclude, and set the DependentUpon property, like so:
itm.Properties.Item("DependentUpon").Value = dependentUponFirstItem;
I've attached the modified sample NetStandardProject.zip
I provide some more information
@DVaughan If the solution is so easy, why isn't MS able to add this simple line to VS within almost three years?
Sorry for the late reply, it took me a while to understand the bug. You're saying that you are grabbing a file-based ProjectItem in the tree, calling ProjectItem.ProjectItems.AddFromFile and expecting that the new item being added to be nested under it? If so, does sound like a missing feature that we haven't implemented. I'll add it the backlog.
Legacy does the following, we need to do the same:
if(m_pNode->IsKindOf(Type_CLangFileNode))
{
CLangFileNode* pNewNode;
pProj->GetHierarchy()->VSITEMID2Node(itemId, (CHierNode**)&pNewNode);
ASSERT(pNewNode && pNewNode->IsKindOf(Type_CLangFileNode));
if(pNewNode && pNewNode->IsKindOf(Type_CLangFileNode))
{
CLangFileNode* pFileParent = static_cast<CLangFileNode*>(m_pNode);
// Need to validate that both files are links, or both are not links
if ( (!pNewNode->IsLinkFile()) && (!pFileParent->IsLinkFile()) )
pNewNode->MakeDependent(pFileParent, FALSE);
else if (pNewNode->IsLinkFile() && pFileParent->IsLinkFile())
pNewNode->MakeDependent(pFileParent, FALSE);
}
}
@davkean any news on this?
@jmarolf @davkean is this related? https://developercommunity.visualstudio.com/content/problem/483587/file-nesting-not-working-for-all-class-or-shared-l.html
Seems it is related: Just tried with 16.7.2 and it's working again - so this issue can be associated with the 16.7 milestone and closed.
We made no changes here to automatically nest items under their parent, if the item did get nested it was because we have default nesting rules and you hit one of them.
@davkean I must have used the wrong project, looks like this is still an issue. Can you pleas reopen it?
This bug is reported many time in other projects that rely on this functionality; only few have found this issue as the root cause of their problems.
So even though this issue has only five thumbs, you should count all the thumbs from all the other issues in other projects that suffer from this bug to calculate the real priority.
I have referenced some of the related issues of e.g. https://github.com/madskristensen/FileNesting. Since even @madskristensen did not find this issue, there are probably many other projects like this.