5

Is it possible to add File as a child of another file in Visual Studio except manually editing project file? I already have MyView.xaml.cs file as a child of MyView.xaml but would like to have MyviewModel.cs as well as a child of MyView.xaml.

MyView.xaml
 |_MyView.xaml.cs
 | 
 |_MyviewModel.cs 
user007
  • 1,122
  • 1
  • 10
  • 30
  • For completeness, if you DID want to do this by manually editing the project, https://stackoverflow.com/a/31921522/5617177 has a good explanation of how to do this. – bwall Aug 09 '18 at 23:39

2 Answers2

7

There are extensions for this that can be downloaded:

NestIn or VSCommands for Visual Studio 2010, Visual Studio 2012 and Visual Studio 2013:

Jarek Kardas
  • 8,445
  • 1
  • 31
  • 32
user007
  • 1,122
  • 1
  • 10
  • 30
0

I don't see any Add File if I right click on a file, and no option to specify where to add it exactly if you are adding one to a project. Probably VS automatically lists files under other files in special cases like the XAML code file, or the Designer file under in case of WinForms, and there's even more. Maybe you can poke around in the csproj manually, but I don't think it's a good idea, unless VS supports it.

If there's a way (other than manually fiddling) I'm curious too.

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
  • 3
    If you right click Project and click "Unload Project", right click again and "Edit Project" you can make file to be child of another one. This is usually the case with design files (Filename.cs, Filename.design.cs or FileName.xaml, FileName.xaml.cs): ToolbarA.xaml ToolbarA.xaml – user007 Sep 02 '13 at 14:48
  • Good to know! I haven't ever used unload project. Does this take the project out from the solution? Every time I have to edit something in csproj files, I open it up in another instance of VS as a file with XML editor. – Csaba Toth Sep 02 '13 at 18:04
  • 1
    If you click "Unload Project" it will keep Project in the solution but it won't have any child elements (fodlers, files ...). It will look like a normal file and "Edit Project" will open it in XML editor. When you finish editing just right click and reload project. – user007 Sep 03 '13 at 08:45