madskristensen / FileNesting

Nest files in Solution Explorer
Other
119 stars 59 forks source link

.NET Standard (Core) projects not working! #82

Closed fahadabdulaziz closed 4 years ago

fahadabdulaziz commented 7 years ago

Installed product versions

Description

Nesting in VS 2017 is not working. I saw in readme file that it is not support. but it really supported!

On any csproj that targets Microsoft.NET.Sdk, edit it to add :

  <ItemGroup>
    <Compile Update="ParentFile.*.cs">
      <DependentUpon>ParentFile.Generated.cs</DependentUpon>
    </Compile>
  </ItemGroup>

I'm not sure but I think it also supported in projects that targets Microsoft.NET.Sdk.Web

Steps to recreate

  1. Select two files
  2. Right click
  3. File Nesting -> Auto-nest selected files!

Current behavior

Do nothing!

Expected behavior

Do nesting and edit the CSProj to be like this:

  <ItemGroup>
    <Compile Update="ParentFile.*.cs">
      <DependentUpon>ParentFile.Generated.cs</DependentUpon>
    </Compile>
  </ItemGroup>
ghost commented 6 years ago

Same here.

RealDotNetDave commented 6 years ago

Me too!

BAlbrich commented 5 years ago

Nesting in this extension is done by adding the file to be nested to the ProjectItems collection of the parent item. That indeed does not work for .Net Standard projects.

To fix it it would need to replace the nesting code with:

setItemAttribute(outputFilePath, "DesignTime", true.ToString());
setItemAttribute(outputFilePath, "AutoGen", true.ToString());
setItemAttribute(outputFilePath, "DependentUpon", parent.Name);
void setItemAttribute(string itemFilePath, string name, string value)
{
   IVsProject vsProject = // get the IVsProject for the item to be nested
   IVsBuildPropertyStorage  buildPropertyStorage  = vsProject as IVsBuildPropertyStorage;

   uint itemId;
   (vsProject as IVsHierarchy).ParseCanonicalName(itemFilePath, out itemId);
   buildPropertyStorage.SetItemAttribute(itemId, name, value);
}

Inspired by this article: https://docs.microsoft.com/en-us/visualstudio/extensibility/persisting-the-property-of-a-project-item?view=vs-2017

I hope this helps.