How do you force Visual Studio to regenerate the .

2019-01-01 06:46发布

Sometimes when I'm editing page or control the .designer files stop being updated with the new controls I'm putting on the page. I'm not sure what's causing this to happen, but I'm wondering if there's any way of forcing Visual Studio to regenerate the .designer file. I'm using Visual Studio 2008

EDIT: Sorry I should have noted I've already tried:

  • Closing & re-opening all the files & Visual Studio
  • Making a change to a runat="server" control on the page
  • Deleting & re-adding the page directive

30条回答
情到深处是孤独
2楼-- · 2019-01-01 06:59

(The following comes from experience with VS2005.)

If you edit an ASPX page while debugging, then the codebehind doesn't get updated with the new classes. So, you have to stop debugging, trivially edit the ASPX page (like add a button or something), then click Design View, then delete the button. Then, your designer files should be updated.

If you are having a different issue with VS2008, then I can't help.

查看更多
看风景的人
3楼-- · 2019-01-01 06:59

Just to add to the long list of answers here - I've just run into this issue in VS2010 (SP1) with an .aspx file. I tried adding and removing standard ASP controls (which has worked in the past) but in the end, I had to remove one of the runat=server lines from an existing control (and save) to force the designer file to regenerate.

查看更多
初与友歌
4楼-- · 2019-01-01 06:59

One thing that nobody's mentioned is to visit the page. I had my designer file stop regenerating because I was including a user control that didn't exist (for various reasons), and none of the things suggested here worked. For whatever reason, I didn't get any errors in Visual Studio - besides the one complaining about the fact that my client-side controls didn't exist because they weren't being regenerated, of course.

It took actually visiting the page to get ASP.Net to tell me the error.

查看更多
爱死公子算了
5楼-- · 2019-01-01 07:00

I've found a way to solve this problem without changing any code or running commands like "Convert to Web Application" - and it's simple too!

What I found was that restarting Visual Studio often solves the problem, but sometimes it doesn't. In those cases, if you close Visual Studio and then delete all content in the "obj" directory for the web project before you open it again, it has always worked for me.

(when started again you just add a space and remove it again and then hit save to have the designer file properly regenerated)

查看更多
梦醉为红颜
6楼-- · 2019-01-01 07:01

Another thing which worked was -

  1. Manually delete & then Create a designer file in filesystem.
  2. Edit Project file.
  3. Add code to include designer
    Eg: <Compile Include="<Path>\FileName.ascx.designer.cs"> <DependentUpon>FileName.ascx</DependentUpon> </Compile>
  4. Reload Project
  5. Open as(c/p)x file in design/view mode & save it.
  6. Check designer file. Code will be there.
查看更多
看淡一切
7楼-- · 2019-01-01 07:02

Here is wat i experienced , Select the website folder right click in the Solution Explorer, select Convert to Web application for all the aspx file a designer file will get generated.

Sameer

查看更多
登录 后发表回答