Detached Designer.cs File in Winforms Project

Designer.cs

For some unknown reason one of my Visual Studio WinForms projects decided to move the "Designer.cs" files on my user controls out to the root of the project hierarchy, next to the forms ".cs".

This broke the visual designer, all you’d get was a blank screen. Interestingly the project would still compile and run just fine with all the controls in place.

Upon inspection of the projects ".csproj" file I found the following:

<Compile Include="FPBinLevelsFolder\BinHistoryFrm.cs">
  <SubType>Form</SubType>
</Compile>
<Compile Include="FPBinLevelsFolder\BinHistoryFrm.Designer.cs">
</Compile>

It was missing the "<DependentUpon></DependentUpon>" tags, note that you leave off the project sub folder.

<Compile Include="FPBinLevelsFolder\BinHistoryFrm.cs">
  <SubType>Form</SubType>
</Compile>
<Compile Include="FPBinLevelsFolder\BinHistoryFrm.Designer.cs">
  <DependentUpon>BinHistoryFrm.cs</DependentUpon>
</Compile>

All my designers are back without any painful recreating of forms.

Leave a Reply

Your email address will not be published. Required fields are marked *