Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我可以在Visual Studio中创建一个位于.Designer.cs文件旁边的文件吗?_C#_.net_Visual Studio 2008 - Fatal编程技术网

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

C# 我可以在Visual Studio中创建一个位于.Designer.cs文件旁边的文件吗?,c#,.net,visual-studio-2008,C#,.net,Visual Studio 2008,在Visual Studio中,在解决方案中创建新的Windows窗体时会创建两个文件(例如,如果创建MyForm.cs,则还会创建MyForm.Designer.cs和MyForm.resx)。后两个文件在解决方案资源管理器中显示为子树 有没有办法将文件添加到Windows窗体类的子树或组中?您需要直接编辑csproj。有一个DependentUpon标记,您必须将其添加为要放置在MyForm.cs下的文件的子标记 例如: <Compile Include="MyForm.MyCoolS

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


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

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

例如:

<Compile Include="MyForm.MyCoolSubFile.cs">
  <DependentUpon>MyForm.cs</DependentUpon>
</Compile>

MyForm.cs

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

<Compile Include="AlertDialog.xaml.cs">
  <DependentUpon>AlertDialog.xaml</DependentUpon>
</Compile>

AlertDialog.xaml

是的,但这有点麻烦-基本上你需要手工编辑项目文件

以下是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>

DataProducerExt.cs
DataProducerExt.cs
DataProducerExt.cs
DataProducerExt.cs
DataProducerExt.cs

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

文件嵌套扩展可以自动执行此操作: