4

So in some cases, like when building WPF windows/user-controls and what not certain file types like .xaml and .cs get combined into "one" file (the .cs file is placed underneath the .xaml).

The problem is that I know this guy that accidentally unbound the two files from each other, and I'm wondering if there is a way to help him put them back together again (or if there is a way to join files like this in general).

sircodesalot
  • 11,231
  • 8
  • 50
  • 83

2 Answers2

14

In the project file (.csproj) edit it like

<Content Include="Default.js">
    <DependentUpon>Default.aspx</DependentUpon>
</Content>

E.g. use the DependentUpon element to nest the file.

See http://davefancher.com/2012/02/23/nesting-files-in-visual-studio/

larsw
  • 3,790
  • 2
  • 25
  • 37
1

If you simply want a way to right click on the file in Solution Explorer in Visual Studio and move it under another file there is an easy way to enable this.

  1. Choose the "EXTENSIONS" menu in from Visual Studio.
  2. Click "Manage Extensions"
  3. On the left, choose "Online" -> "Visual Studio Marketplace"
  4. Search for File Nesting
  5. Install the "File Nesting" package from Mads Kristensen
  6. Restart Visual Studio.

Now you can select a group of files in Visual Studio Solution Explorer, right click on them, and "File Nesting" is an option on the menu. It will also enable "auto-nesting" for particular types of files.

I am not associated with Mads but their solution worked will for me.

Joshcodes
  • 8,513
  • 5
  • 40
  • 47