Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio opens my class-file (.cs) in the designer mode

Tags:

I've created a class that extends DbConnection in a brand new project.

public class FakeDbConnection : DbConnection { ... } 

In the Solution Explorer the class looks like this: enter image description here

And when double-clicking it wants to open it in design mode which won't work. Opening up the .csproj-file reveals the problem

<ItemGroup>   <Compile Include="FakeADO\FakeDbConnection.cs">     <SubType>Component</SubType>   </Compile> </ItemGroup> 

Even if I remove the SubType tag VS2010 immediately re-adds it. Very annoying.

How can I stop VS2010 from opening up my .cs file in designer mode and just open it up as a regular code file?

like image 304
vidstige Avatar asked Aug 09 '12 09:08

vidstige


People also ask

How do I open a .CS file in Visual Studio?

Start from a project If your program code is already in a Visual Studio project, open the project. To do so, you can double-click or tap on the . csproj file in Windows File Explorer, or choose Open a project in Visual Studio, browse to find the . csproj file, and select the file.

What is designer CS file in C#?

The designer file (. Designer. cs) is a code file automatically generated by your designer to hold the form's layout information that was created using the Visual Studio IDE. Once you add a new form in your application, VS will automatically generate the designer file for this form.

How do I open designer Cs in Visual Studio?

cs [Design] , which contains the drag&drop controls. If you are directly in the code behind (The file named Form1. cs , without "[Design]"), you can press Shift + F7 (or only F7 depending on the project type) instead to open it.


1 Answers

As described in an answer to this question you can do this:

[System.ComponentModel.DesignerCategory("Code")] class FakeDbConnection: DbConnection { ... } 

Important: The attribute needs to be fully qualified otherwise VS2010 will ignore this.

Important (thanks to jmbpiano): The attribute only applies to the first class in the file.

like image 177
vidstige Avatar answered Oct 02 '22 16:10

vidstige