With recent versions of Xamarin Studio it is not currently possible to nest files without directly editing the project file. In the past it was possible to drag and drop a file so it was then nested inside another file.
Visual Studio also does not support nesting files by using drag and drop howeverMads Kristensen created a File Nesting extension that adds support for manual and automatic nesting of files within Visual Studio. There is a demo video of the File Nesting extension that shows the extension being used with Visual Studio. This extension has now been ported to Xamarin Studio and is available from the MonoDevelop Add-in Repository.
Let us take a walkthrough of the features of the File Nesting addin for Xamarin Studio.
- Manual file nesting
- Manual file un-nesting
- Automatic file nesting of selected files based on rules
- Automatic file nesting when files are added to a project
- Options to specify which file nesting rules are applied
- Xamarin Studio 6.0 or MonoDevelop 6.0.
Manual File Nesting
To manually nest a file select it in the Solution window then right click and select File Nesting – Nest Item…
This will open a file nesting dialog where the parent file can be selected.
Select the parent file and click OK to nest the file under that parent file.
You can also nest multiple files under a parent by selecting multiple files in the Solution window and selecting the Nest Item menu.
Manual File Un-nesting
To un-nest a file select it in the Solution window then right click and select File Nesting – Un-nest Item.
The file will then be un-nested from its parent.
Automatic Nesting Rules
The file nesting rules are available from the Preferences dialog.
Each rule has a tooltip which will show more detailed information about what the rule does.
The Enable auto-nesting option will enable or disable automatic file nesting when a file is added to a project.
Enable extension rule
This rule will nest files added with an extra extension under their corresponding parent file. For example MyView.xaml.cs nests under MyView.xaml.
Enable interface implementation rule
This nests C# interface implementations under the corresponding interface based on the filename. For example, if there is an interface file IMyInterface.cs then a new file called CustomMyInterface.cs will be nested under the IMyInterface file.
Enable known file type rule
This nests certain known files types. For example, MyPage.ts will be nested under MyPage.html.
Enable path segment rule
This nests files with an added path segment under its parent. For example, MyFile.Designer.cs nests under MyFile.cs.
Automatic Nesting of Selected Files
To automatically nest files, based on the enabled file nesting rules, select the files, or folder, or project, then right click and select File Nesting – Auto-nest selected items.
This will then apply the enabled file nesting rules to the selected files.
Automatic File Nesting on Adding Files
To enable automatic file nesting when files are added right click the project and select File Nesting – Enable automatic nesting.
A check box will be displayed next to this menu item if this feature is enabled. Now when a file is added the enabled nesting rules will be applied and the file will be automatically nested.
The File Nesting addin is available from the MonoDevelop Add-in Repository on the beta channel. To install the addin open the Add-in Manager, search for the File Nesting addin, then click the Install button.
After installing the addin Xamarin Studio will need to be restarted for the addin to work correctly.