Project-system: Automatically nest *.Designer files

Created on 17 May 2017  路  3Comments  路  Source: dotnet/project-system

Possibly a dupe of #1272, but filing again for the more general scenario.

Whenever a *.Designer.cs file is added to a project, it should automatically nest under its parent of the same name.

This used to work in xproj, but the functionality never made it into the new project system.

This is important for EF Core since each migrations adds two files (e.g. MyMigration.cs and MyMigration.Designer.cs) and the list of items under the Migrations folder is twice as long as it is on other project types.

The workaround, of course, is to add the following to your csproj.

<ItemGroup>
  <Compile Update="MyMigration.Designer.cs">
    <DependentUpon>MyMigration.cs</DependentUpon>
  </Compile>
</ItemGroup>
Resolution-Duplicate

Most helpful comment

Since I ended up here a work around for this is

<ItemGroup>
    <Compile Update="**\*.Designer.cs">
      <DependentUpon>$([System.String]::Copy("%(Filename)").Replace(".Designer","")).cs</DependentUpon>
    </Compile>
  </ItemGroup>

All 3 comments

Since I ended up here a work around for this is

<ItemGroup>
    <Compile Update="**\*.Designer.cs">
      <DependentUpon>$([System.String]::Copy("%(Filename)").Replace(".Designer","")).cs</DependentUpon>
    </Compile>
  </ItemGroup>

@Tarig0 awesome, thanks!

Was this page helpful?
0 / 5 - 0 ratings