views:

407

answers:

4

I'm upgrading a project from Visual Studio 2003 to 2008 and wish to automatically generate XXX.Designer.cs files and update the corresponding XXX.cs original one.

Any automatic way to do it?

UPDATE: I'm referring to WinForms. Of course, I know the old style works but i'm looking for a way to go to the new style without doing it by hand.

A: 

I'm not sure I understand, but I'll make a guess.

Was this an ASP.NET project in VS2003? Did it have .Designer.cs files in it? Is it the case that you've done an upgrade but you find that you have no .Designer.cs files now?

If so - you may have inadvertently changed your Web Application Project into a Web Site "project". This sort of "project" was introduced in VS2005, so you would not have seen it yet. These aren't real projects (no .csproj file), and they have many other differences.

Otherwise, if your project didn't used to have .Designer.cs files, then why do you want them now?

In general, the way to create designer files is to open the file in a designer, wait a few moments for the designer to finish what it's doing (updating the screen, etc); and then saving the file. You might possibly have to "touch" the original in order to get the designer to reevaluate things.

John Saunders
VS2003 didn't have .designer.cs files because .net 1.1 didn't support partial classes. So it just put control declarations hidden within a region in the codebehind. FerranB is asking for an automated way to move these declarations to a designer file.
Mauricio Scheffer
It's been so long since I've used VS2003 that I had forgotten! In that case, openning into the Designer, then saving will do it manually. There may be a way to automate that, either through macros or stronger VS extensibility. Macros will probably do it.
John Saunders
nope, neither VS2005 or VS2008 does automatically move things to .designer files just by opening and saving.
Mauricio Scheffer
(at least with ASP.NET projects)
Mauricio Scheffer
A: 

The original classes will continue to work - even with the Visual Studio designer. The code the VS puts in the Designer classes is simply meant to remove the designer "noise" into a separate file so you can focus on the non-visual code in your class.

Once you migrate the project to VS2008 using the wizard, you can open up your forms in VS and continue to edit them just like you did before. Any new forms that you create will get Designer backer files.

Paul Alexander
A: 

We had this problem.

Basically the designer file should contain nothing but a set of object declarations (i.e. the objects on the form) and the InitializeComponent() call. If you've done any fancy work on your constructor that might be there too.

Simply create a file called MyForm.Designer.cs and add it to the project. VS2008 will automatically place it underneath MyForm.cs. From there, if you create the partial class heading and the namespace, then copy across all the declarations and Initializecomponent call into the designer file, then it will work.

But because if you had to, people would edit initializecomponent and also edit the default constructor, VS2005 and 2008 couldn't automatically upgrade these files as all sorts of strange things might occur. I guess from a project point of view, what benefit do you think your working code will derive from the separation?

Spence
+1  A: 

There is a macro out there floating that does this. I have used it and it works great. Start by looking at Nathan Jones Blog. If you dont have much luck then download a zip of the macro source (I posted) from VSCONVERT.ZIP - FileFactory

jalexiou