Community.VisualStudio.Toolkit icon indicating copy to clipboard operation
Community.VisualStudio.Toolkit copied to clipboard

add nested file in legacy style csproj does NOT working

Open lsoft opened this issue 4 years ago • 0 comments

Description

VS2019 16.11

PhysicalFile.AddNestedFileAsync is not working for legacy style csproj, at least in my https://github.com/lsoft/NestedUnitTests (see ProcessLegacyStyleProjectAsync method). Technically, it's working but I need to unload/reload project to see the new file to be nested. Without that, the file is listed at the same level in the tree.

when I switch back to

            var rootDocumentItem = dte.Solution.FindProjectItem(rootDocumentItemFilePath);
            rootDocumentItem.ProjectItems.AddFromFile(childDocumentItemFilePath);

I do not need to unload/reload project, the file adds as nested "automatically".

So, I see here 2 troubles/questions.

  1. How can the code above be re-implemented without DTE?
  2. Probably, we need to modify PhysicalFile.AddNestedFileAsync to support both types of csproj.

How to repro

  1. Run https://github.com/lsoft/NestedUnitTests to your Exp instance of VS.
  2. Open class lib with legacy styled project.
  3. Try to add nested file (RMB click on any regular cs file and choose latest command in the menu)
  4. Notice, the added file is nested.
  5. Replace the DTE-approach with the community SDK approach in ProcessLegacyStyleProjectAsync.
  6. Run vsix, and repeat the action. Notice that added file will not be nested. Unload/Reload project and the file is nested now.

Thanks for this SDK, guys. It's great!

lsoft avatar Sep 05 '21 17:09 lsoft