7

当我在处理 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

(不介意命名,当然我会给它一些有区别的命名)

如何解决这个问题?我在这个上查了谷歌,但找不到这么快的答案......

4

2 回答 2

1

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.

于 2010-05-27T05:55:55.797 回答
1

您可以阅读评论,它们会告诉您该怎么做。

将声明移动到您的代码隐藏并删除设计器文件。

但我必须做一个观察:

这种担忧的表达,尤其是试图消除 VS 向你展示的善意所付出的努力,掩盖了一定程度的天真和缺乏经验。

也许你的时间会花在编码上?;-)

于 2010-05-26T21:51:22.350 回答