Is it possible to tell Visual Studio not to treat a source file as a “component”? [duplicate]

ぐ巨炮叔叔 提交于 2019-12-03 10:34:21

Can't you use the DesignerCategory attribute to decorate your class ?

When decorating your class with this attribute like displayed below, the file should open in 'code view' when you double click it:

[System.ComponentModel.DesignerCategory("Code")]
public class MyComponent
{
}

As OregonGhost already mentioned in his comment this also happens if you make a partial class file from a form.

The problem is even more worse. If you take a look into your project file you can find entries for every file include like this:

<Compile Include="FormMain.cs">
  <SubType>Form</SubType>
</Compile>

So the solution should be to delete the line <SubType>...</SubType> cause it seems to be the root of all the problems. But if you delete this line, save the file, open it in Visual Studio, save it again and take a look again into, the line will reappear!

There seems to be only one hard-coded exception within Visual Studio and this is *.Designer.cs. So there is no solution to accomplish this problem.

You could right-click the source file, choose "View Code", then click "Set as Default". It's a bit of a blunt instrument, but if you have more false components in your solution than real components, then you may find it convenient.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!