Microsoft 开发人员网络 > 论坛主页 > Visual C# IDE > Forcing regeneration of the designer.cs file
提出问题提出问题
 

已答复Forcing regeneration of the designer.cs file

  • 2007年8月24日 16:10Lucidquiet 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    Hello:

     

    Occassionally I update the ascx file and the new control, or a rename of a control's ID isn't reflected in the .designer.cs file.  How do I force the IDE to regenerate this source code file?

     

    Also various machines in the office generate comments for this code while other setups don't generate comments.  Where is the setting for turning this on or off?

    L-

答案

  • 2007年8月25日 11:59TaylorMichaelLMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    The designer works a little weird.  I would say it is a bug but it doesn't behave the way it should but it is pretty easily to replicate.  Check at http://connect.microsoft.com to see if it has been reported.

     

    Whenever you modify the ASCX file it is suppose to update the designer.cs file.  However this updating doesn't occur instantly.  Instead it occurs when you later open the designer file.  If you don't open the designer file then it won't get updated normally.  If you set a property on the control it'll generate update the designer file as well.  It is almost hit and miss when it'll update the designer file.  Needless to say if you open the designer file and save it outside of saving the ASCX file then it can easily get out of sync.  In the right circumstances it won't generate comments or even variables for the controls.  Here are some scenarios I can replicate starting with a new ASCX file.

    1. Correct Behavior
      1. Add a new control to the ASCX file.
      2. Open the designer file.
      3. Save All files.
      4. The designer file contains the comments and variable for the control.
    2. Empty Designer File
      1. Add a new control to the ASCX file.
      2. Open the designer.  Notice a variable w/ comments was added.
      3. Close the designer.  Say No to the save prompt.
      4. Save all files.
      5. Open the designer file and notice the variable is gone again.  It appears that the IDE gets confused about the modify state of the designer and assumes it is not dirty.
    3. Missing Controls
      1. Add a new control to the ASCX file.
      2. Save the file.
      3. Open the designer file.
      4. Switch to the ASCX file and add another control.
      5. Save the ASCX file.
      6. Switch to the designer file.
      7. Close w/o saving.
      8. Open back up the ASCX and designer files.
      9. The controls will be out of sync until the ASCX file is modified again.
    4. Designer file w/o comments
      1. I replicated this issue really easily but I don't remember how I did it.

    As far as preventing the comments I don't think you can. 

     

    My recommendation is to avoid opening the designer file at all.  In the few cases where you might open it be sure to always save changes even if you haven't made any.  If ever in doubt then add and then remove a control from the ASCX file to regenerate the designer.  It is almost always best to leave the designer file closed.

     

    Michael Taylor - 8/25/07

    http://p3net.mvps.org

全部回复

  • 2007年8月25日 11:59TaylorMichaelLMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     已答复

    The designer works a little weird.  I would say it is a bug but it doesn't behave the way it should but it is pretty easily to replicate.  Check at http://connect.microsoft.com to see if it has been reported.

     

    Whenever you modify the ASCX file it is suppose to update the designer.cs file.  However this updating doesn't occur instantly.  Instead it occurs when you later open the designer file.  If you don't open the designer file then it won't get updated normally.  If you set a property on the control it'll generate update the designer file as well.  It is almost hit and miss when it'll update the designer file.  Needless to say if you open the designer file and save it outside of saving the ASCX file then it can easily get out of sync.  In the right circumstances it won't generate comments or even variables for the controls.  Here are some scenarios I can replicate starting with a new ASCX file.

    1. Correct Behavior
      1. Add a new control to the ASCX file.
      2. Open the designer file.
      3. Save All files.
      4. The designer file contains the comments and variable for the control.
    2. Empty Designer File
      1. Add a new control to the ASCX file.
      2. Open the designer.  Notice a variable w/ comments was added.
      3. Close the designer.  Say No to the save prompt.
      4. Save all files.
      5. Open the designer file and notice the variable is gone again.  It appears that the IDE gets confused about the modify state of the designer and assumes it is not dirty.
    3. Missing Controls
      1. Add a new control to the ASCX file.
      2. Save the file.
      3. Open the designer file.
      4. Switch to the ASCX file and add another control.
      5. Save the ASCX file.
      6. Switch to the designer file.
      7. Close w/o saving.
      8. Open back up the ASCX and designer files.
      9. The controls will be out of sync until the ASCX file is modified again.
    4. Designer file w/o comments
      1. I replicated this issue really easily but I don't remember how I did it.

    As far as preventing the comments I don't think you can. 

     

    My recommendation is to avoid opening the designer file at all.  In the few cases where you might open it be sure to always save changes even if you haven't made any.  If ever in doubt then add and then remove a control from the ASCX file to regenerate the designer.  It is almost always best to leave the designer file closed.

     

    Michael Taylor - 8/25/07

    http://p3net.mvps.org

  • 2007年9月11日 18:10RandWro 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    I have had major issues in VS05 with a few pages where controls were not being recognized in the codefile, and also third-party DLL's were not being loaded  (" the namespace... did not load any ... controls").  I could go back and forth with  Design and Source views, but in one case had no aspx.designer.vb file at all. At no time did I edit the designer files. I thought it was a memory issue that the large third party controls were not being loaded.  Eventually, I had larger pages work fine.

     

    The one thing that forced the designer file to be populated was to create an empty one and explicitly add it to the project, then various back and forths w Designer and Save.  However, the same problems of controls (labels, etc.) not being recognized in code (though they were in the designer.vb file) and of DLL's not loading persisted (with much teeth-grinding).  The good news: starting over with a fresh file and adding in each ASPX element has worked.

     

    The difference appears to be the use of <span> and possibly <div> elements.  Here's a snippet:

    <div>
            <span style="font-family: Arial">
            <asp:Label ID="lblHideJS" runat="server"  color = white > </asp:Label>
    Welcome: <b><asp:Label ID="lblName" runat="server" Text="User"></asp:Label></b>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Label ID="lblProxy" runat="server" Text="Proxy:" Visible = False></asp:Label> 
    <aspBig SmileropDownList ID="ddlProxy" runat="server" Width="170px" Visible=false>
                      <asp:ListItem>[none]</asp:ListItem>
                      <asp:ListItem>Farrell, John</asp:ListItem>
                      <asp:ListItem>Stewart, Carol</asp:ListItem>
                      </aspBig SmileropDownList>
                <br />
                &nbsp;<br /><p></p>

     

    Nothing unusual, right?  Designer did not complain about end tags, or anything.  I could supply the whole files if MS wanted to test it, but the bottom line is that this ostensibly Designer-compatible aspx file totally got Designer "wrapped around the axel" with these inexplicable errors. Instead of my beating my head against the wall, the wall was beating on me.  My advise: watch out for span (and div?) usage!

    - Rand W.

  • 2007年10月17日 14:35ChR 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    The OP asked how to cause the designer to regenerate.

    I too have this issue, and its driving me up the wall to spend 45 mins designing an extensive WUC only to find out that I have to add each of my fields by hand to the designer file.  This issue happens to me rather consistantly on Vista with vs2k5 sp1.

    I dont care if MS adds a menu option when you right click an ascx/aspx page that Regens the designer file, but this is ridiculous.


    IS there a method for regenerating the designer.* files???
  • 2007年10月17日 14:44TaylorMichaelLMVP, 版主用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    The file gets regenerated whenever a control is modified in the ASPX/ASCX page or during compilation.  If you delete the original designer.cs file and then modify the ASPX/ASCX page then it should be regenerated.  Note that if the designer file does not appear under the ASPX/ASCX page in SE then it probably won't work properly.  Also note that you should rarely open the designer file directly.  If the designer file is open in the IDE then it will cause problems.

     

    Michael Taylor - 10/17/07

    http://p3net.mvps.org

     

  • 2007年10月19日 14:50John Q. Smith 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     建议的答复
    A pain in the #@$$.

    Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application.
  • 2008年4月3日 19:48musicdsign 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    "Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application."

     

    Now there is the solution I was looking for and it works! Just simple and to the point.

     

    Thanks, John!

     

    David

  • 2008年6月16日 23:22Tom von Alten 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    "Delete the designer.cs page, right click on the aspx/ascx page and choose Convert to Web Application."

    That was the tip I needed to find my similar problem, too. It didn't SOLVE the problem, but it REVEALED it: upon the attempt to regenerate the designer.cs file, I got this error monologue:

    Generation of designer file failed: Control btnUpdate conflicts with field BTNUPDATE of a different case. Declaring both fields will result in an ASP.NET error.

    Turns out VisualStudio 2005 has an odd case insensitivity. I had various constant strings that I'm using to change button .Text depending on the state of the form. I changed those to start with BTN_ instead, and all was well.

  • 2008年12月9日 15:54fbalazs1 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     建议的答复

    If there are errors int the aspx markup the designer may fail to generate the code control members. So you should check that the aspx file does not contains errors, then use the "convert to web applictaion" command.

    Hope this helps.

  • 2009年9月25日 5:37MarlonBohol 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     建议的答复
    The above workaround didn't work with me. i am not successful. but the following did.

    1) Change into designer mode
    2) make a change (just modify some text or something)
    3) save the file.

    the following link is the source of this workaround.
    http://blogs.blackmarble.co.uk/blogs/msteeples/archive/2009/05/20/visual-studio-does-not-update-the-asp-net-designer-cs-file.aspx


    hope this helps.

  • 2009年10月13日 15:16Matthew Lamb 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     
    Another way to regenerate your designer file:

    1. Create another new blank ascx (or aspx, as applicable)
    2. Switch to design mode in your 'broken' file.
    3. Select All, and Copy to clipboard
    4. Paste all the controls into the new file.
    5. Delete the controls from the original file, and copy and paste the controls back in from the new file

    This just worked great for me.

  • 2009年10月15日 4:23Funcall-of-Nil 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    None of these work in VS 9.0.30729.1.

    This subject covers the number one bug in Visual Studio as far as I'm concerned. I have had more time wasted because of this than any other glitch (the second being the inability to find a clearly specified reference). I have tried all of the aforementioned remedies with no success. The only way to solve this is to include all of the prototypes in my .cs file and abandon the designer file entirely. That's kind of old-school, but it works.

    The VStud team really needs to add a "force generate" option into one of the menus to MAKE the tool rebuild everything.

  • 2009年10月30日 2:40knroc 用户奖牌用户奖牌用户奖牌用户奖牌用户奖牌
     

    I had a similar problem.  I noticed that there was no namespace defined in the aspx file nor in the aspx.cs file.  I added the declaration to both files and the designer.cs file was generated fine doing the convert to web application.