Eim
Eim

Reputation: 39

C# Form1.cs no longer showing in Solution Explorer

I am new to programming and am working on a C# project and my form1.cs is no longer in my solution explorer. It does however show in class view. I have tried right clicking and adding existing item but this doesn't work. Is it possible to get the form1.cs back from class view into solution explorer? Thanks.

Upvotes: 3

Views: 4370

Answers (4)

Salem
Salem

Reputation: 1

Right-click and select "Exclude From Project" then Right-click and select "Include In Project" the same model; And you will see the file

Upvotes: 0

Xan-Kun Clark-Davis
Xan-Kun Clark-Davis

Reputation: 2843

I had the same Problem and was struggling with it quite a while. I solved it by installing the desired target framework (in my case .NET 4.5.1) manually (from offline installer) AND the .NETCoreApp components (from "modify" in the VS installer).

Then I created a new solution with a console project in it and set the target framework to .NET 4.5.1.

When I now create a new Forms project, everything is back to normal (it uses 4.5.1 by default) and the Forms.cs file shows up in solution explorer.

I will try if I can fix my broken projects that way too...

In my .csproj file there was no

<EmbeddedResource Include="Form1.resx">
      <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>

Not before and not after the Form.cs was shown.

Upvotes: 0

Stuart
Stuart

Reputation: 764

It may be that the form has got excluded from your project. At the top of your Solution Explorer, click "Show All Items".

enter image description here

If the form then appears, right click it and select "Include In Project".

UPDATE From what has been said, it sounds like the Form.cs file may have got "disconnected" from the designer and resx files. Close Visual Studio and open the .csproj file in an XML editor or just Notepad and check that you have something resembling the following in an "ItemGroup" element.

<Compile Include="Form1.cs">
    <SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
      <DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
      <DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>

Make any changes required and then re-open your solution.

Upvotes: 0

Pavel Kharibin
Pavel Kharibin

Reputation: 765

Try to click "Show all items" button on top of Solution Explorer, it will show all files that not in your project. And if your Form.cs will appear then right click on it and select "Include in project" menu.

Upvotes: 1

Related Questions