Renaming things in Visual Studio

August 14, 2007 at 7:03 am | Posted in Visual Studio | 9 Comments

Many newcomers to Visual Studio experience the problem of breaking their application after renaming something.  I certainly have!  First, there are many different names that are used to tag different things (see list below); second, there are multiple ways of renaming things and the impact on the IDE are not always clear to the novice; third, renaming things can sometimes confuse the Designer and your program because of references to names in the Designer generated code and helper files.

Here are some general guidelines that work for me:

1. It is always easier to name things when you first add them to your project. This includes everything from the initial project name to the controls you drag to your form from the toolbox.

2. Before renaming things like Classes, UserControls, NameSpaces, Assemblies etc, back up your project. This can be easily done in the Windows Explorer by making a copy of the Solution Folder for the project (found in your VS Projects Folder).

3. To change the name of something in your user code such as NameSpace, Class or UserControl, select an instance of the name in your code editor and use the Refactor > Rename function. You may have to rebuild the solution after this to get things back to normal.

4. To change the name of the Solution File or Project File, use the Solution Explorer and right click > Rename.

Here is a list of various high-level names that one might want to manage:

Solution Folder – this is the name of the top folder in the ..\Visual Studio 2005\Projects Folder. Change in Windows Explorer. Note that it is possible that this will confuse the Recent Projects Start Page but you should be able to use Open …Projects to find it.

Project Folder – this is the name of the folder(s) inside the Solution Folder with project data. (A solution can have more than one project.) Change in Windows Explorer. Note that it is possible that this will confuse the Recent Projects Start Page but you should be able to use Open …Projects to find it.

Solution File – the name of the solution. Change in the Solution Explorer, right-click Rename. Note that it is possible that this will confuse the Recent Projects Start Page but you should be able to use Open …Projects to find it.

Project File – the name of the project. Change in the Solution Explorer, right-click Rename. Note that it is possible that this will confuse the Recent Projects Start Page but you should be able to use Open …Projects to find it.

Assembly Name – as found in Properties > Application. This will be the name of your .exe file. Change in the Properties >Application dialog.

NameSpace – also in Properties >Application and in your code. This is useful for keeping your class and control names distinct from other code bases. Change using the Refactor.

Title – as found in Properties>Application>Assembly Information. This will be put in the title bar of the AboutBox. Change in the Assembly Information Dialog.

Product – also as found in Properties>Application>Assembly Information. This will be a name listed in the AboutBox. Change in the Assembly Information Dialog.

Advertisements

9 Comments »

RSS feed for comments on this post. TrackBack URI

  1. yeah, I think it’s a shame that renaming solutions and projects has to be so tricky.

    I’m working on a project at work … as it gets bigger and starts to include more, the main project name doesn’t reflect the purpose so much anymore… but I’m not eager to start screwing with things yet.

    … Nice blog! I’m blog-Rolling you :)

  2. Which property defines “long friendly description” for a file. Specifically I have developed a C# screensaver, but am limited to 8 char filename of .scr file as deployed to windows/system32 dir. I cannot find property to define a “long friendly description” – which will display in windows list of screeensavers. I tried “assembly name” but doesn’t seem to make any difference. Any ideas?
    Jim

  3. Jim,

    Sorry, I don’t havve an answer for your short filename question. Perhaps you could ask here:

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=160&SiteID=1

  4. Excellent post – thanks for the clear, simple cheat sheet

    :-)

  5. It’s quite amazing that there is not normal facility as in Java IDE’s for such a simple task. I’ve been doing something in C and searching tirelessly the “Refactory” icon in VS ;) or something of that sort. Sometimes Microsoft are just incredibly incompetent.

  6. Hopefully links are ok but I have just renamed my VS BIDS project and solution including the references… e.g. physical folders.

    The below website outlines the steps.

    http://www.platinumbay.com/blogs/dotneticated/archive/2008/01/01/renaming-and-copying-projects-and-solutions.aspx

  7. Thanks – you saved my life!

  8. Been there, broken that. Great cheat sheet! Many thanks.

  9. […] to dotUpdate(), various ways to rename a project in […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: