将代码文件移到项目中的另一个文件下

时间:2014-12-10 09:50:04

标签: c# visual-studio projects-and-solutions csproj

我想将一个代码文件移动到另一个相关文件的组下,如下所示:

code file grouping

如您所见,SingleObjectViewModel.Commands.cs隐藏在SingleObjectViewModel.cs组中。在某些情况下它可能很有用。

我已创建SingleDocumentViewModel.Commands.cs但在Visual Studio中进行简单的拖放操作无法正常工作。

如何实现它?

1 个答案:

答案 0 :(得分:0)

我找到了一种方法,但它不是用户友好的,需要手动编辑项目文件。我不确定它是否适用于其他版本的Visual Studio(MS Visual Studio 2013)

首先,卸载项目(右键单击项目,Unload Project)。

然后修改csproj文件(再次右键单击,Edit *.csproj

在编辑器中,替换:

<Compile Include="SingleDocumentViewModel.Commands.cs">

<Compile Include="SingleDocumentViewModel.Commands.cs">
  <DependentUpon>SingleDocumentViewModel.cs</DependentUpon>
</Compile>

然后保存已编辑的文件并再次加载项目(右键单击它,Reload project)。

现在文件已分组:

grouped files