【问题标题】:Move code file under another file in project将代码文件移动到项目中的另一个文件下
【发布时间】:2020-05-06 12:20:19
【问题描述】:
我想将一个代码文件移动到另一个相关文件的组下,如下所示:
如您所见,SingleObjectViewModel.Commands.cs 隐藏在 SingleObjectViewModel.cs 组中。在某些情况下它可能很有用。
我已经创建了SingleDocumentViewModel.Commands.cs,但在 Visual Studio 中简单的拖放操作不起作用。
如何实现?
【问题讨论】:
标签:
c#
visual-studio
projects-and-solutions
csproj
【解决方案1】:
我找到了一种方法,但它对用户不友好,需要手动编辑项目文件。我不确定它是否适用于其他版本的 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)。
现在文件已分组: