我可以在Visual Studio中创建一个位于.Designer.cs文件旁边的文件吗?

pia*_*an0 7 .net c# visual-studio-2008

在Visual Studio中,在解决方案中创建新的Windows窗体时会创建两个文件(例如,如果创建MyForm.cs,则还会创建MyForm.Designer.cs和MyForm.resx).这两个后两个文件在解决方案资源管理器中显示为子树.

有没有办法将文件添加到Windows Form类的子树或组?

San*_*ino 14

在编辑模式下打开.csproj,查找您想要在另一个文件下的文件,并添加DependentUpon元素,如下所示:

<Compile Include="AlertDialog.xaml.cs">
  <DependentUpon>AlertDialog.xaml</DependentUpon>
</Compile>
Run Code Online (Sandbox Code Playgroud)


Jef*_*tes 6

您需要直接编辑csproj.有一个DependentUpon标记,您必须将其添加为要放在MyForm.cs下的文件的子标记.

例:

<Compile Include="MyForm.MyCoolSubFile.cs">
  <DependentUpon>MyForm.cs</DependentUpon>
</Compile>
Run Code Online (Sandbox Code Playgroud)


Jon*_*eet 5

是的,但是有点麻烦——基本上你需要手动编辑项目文件。

以下是我和 Marc Gravell 共同参与的一个项目的示例:

<Compile Include="Linq\Extensions\DataProducerExt.cs" />
<Compile Include="Linq\Extensions\DataProducerExt.SingleReturn.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Grouping.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Pipeline.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Conversion.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
<Compile Include="Linq\Extensions\DataProducerExt.Math.cs">
  <DependentUpon>DataProducerExt.cs</DependentUpon>
</Compile>
Run Code Online (Sandbox Code Playgroud)

请注意每个依赖项中的“DependentUpon”元素。这在 VS 中正确显示,以 DataProducerExt.cs 作为父级。