ASP.NET 自动生成 aspx.designer.cs 关闭吗?
当我正在开发一个 asp.net/c# 项目时,我遇到了自动生成其内容的 foobar.aspx.designer.cs。例如,当我更改代码/设计器时,designer.cs 会自动更新其内容。
由于我是一个控制欲强的人,我想自己维护代码。我对我不需要的评论过多感到不满意。喜欢:
/// <summary>
/// Form1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm Form1;
虽然我想看到以下内容:(
protected global::System.Web.UI.HtmlControls.HtmlForm Form1;
protected global::System.Web.UI.WebControls.Button Button3;
etc, etc
不介意命名,当然我会给它一些区别命名)
如何解决这个问题?我查了谷歌这个问题,但没能这么快找到答案......
As I'm working on a asp.net/c# project, I'm confronted with the foobar.aspx.designer.cs that auto generates it's content. eg, when I'm changing the code/designer, the designer.cs automatically updates it's content.
As I'm bit of a control-dude, I'd like to maintain the code myself. I'm not happy with the overkill of comments I don't need. Like:
/// <summary>
/// Form1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm Form1;
While I'd like to see the following:
protected global::System.Web.UI.HtmlControls.HtmlForm Form1;
protected global::System.Web.UI.WebControls.Button Button3;
etc, etc
(don't mind the naming, ofcourse I'd give it some distinguishing nameing)
How to fix this? I checked google on this one, but couldn't find an answer so quickly...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您是否可以禁用该文件的自动生成。这样做是否是个好主意......如果你真的想(需要?)干扰它,我宁愿寻找一种方法来改变它的行为/格式。不幸的是我也无法为此提供解决方案/提示。不过,您可能需要查看“自定义工具”(用于代码生成)领域。
为什么您对文件的格式如此不满意?我几乎从来没有看过它 :) 根据 Scott Guthrie 的说法,设计器文件已在 VS 2005 中作为“允许 Visual Studio 编写‘丑陋’代码的地方”引入: 教程 2:VS 2005 Web 应用程序项目的代码隐藏。
编辑:也许 Scott Hanselman 的这篇文章会有帮助? T4(文本模板转换工具包)代码生成 - 最佳保守的 Visual Studio 秘密。
I am not sure if you can disable the automatic generation of this file. Nor if it would be good idea to do so... If you really want (need?) to interfere with it I would rather look for a way to change its behaviour/format. Unfortunately I cannot provide a solution/hint for this either. You might have to look in the field of "custom tools" (for code generation) though.
Why are you so unhappy with the format of the file? I almost never even look at it :) And according to Scott Guthrie the designer file has been introduced in VS 2005 as "a place where Visual Studio is allowed to write 'ugly' code": Tutorial 2: Code-Behind with VS 2005 Web Application Projects.
Edit: Maybe this article by Scott Hanselman could be of any help? T4 (Text Template Transformation Toolkit) Code Generation - Best Kept Visual Studio Secret.
你可以阅读评论,他们告诉你该怎么做。
将声明移至代码隐藏并删除设计器文件。
但我必须提出一个观察:
这种关心的表达,尤其是试图消除 VS 向你展示的善意所付出的努力,掩盖了一定程度的天真和缺乏经验。
也许你的时间花在编码上会更好? ;-)
You could read the comments, they tell you what to do.
Move the declarations to your codebehind and delete the designer file.
But I have to make an observation:
Expression of this kind of concern and especially the expenditure of effort in trying to undo the kindness that VS is showing you belies a degree of naiveté and inexperience.
Perhaps your time would be better spent coding? ;-)