2008-10-21 10 views
7

W programie Visual Studio dwa pliki są tworzone po utworzeniu nowego formularza systemu Windows w rozwiązaniu (np. Po utworzeniu plików MyForm.cs zostaną również utworzone pliki MyForm.Designer.cs i MyForm.resx). Te dwa pierwsze pliki są wyświetlane w eksploratorze rozwiązań jako poddrzewo.Czy mogę utworzyć plik, który znajduje się obok pliku .Designer.cs w Visual Studio?

Czy istnieje sposób dodawania plików do pod-drzewa lub grupy dla klasy formularza Windows?

Odpowiedz

14

Otwarte .csproj w trybie edycji, poszukaj pliku, który ma być pod inną, i dodać element DependentUpon, tak:

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

Rozszerzenie FileNesting może to zrobić automatycznie: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileNesting – John

6

Musisz bezpośrednio edytować csproj. Jest tag DependentUpon, który musisz dodać jako znacznik podrzędny pliku, który chcesz umieścić w MyForm.cs.

Przykład:

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

Tak, ale to trochę kłopotliwe - w zasadzie trzeba ręcznie edytować plik projektu.

Oto przykład z projektem, który Marc Gravell i ja praca na:

<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> 

Uwaga „DependentUpon” element w każdym z zależnościami. Wyświetla się odpowiednio w VS, a DataProducerExt.cs jako nadrzędny.

Powiązane problemy