Using an existing app as a template, ASP.NET MVC

This document teaches you how to use an existing app as a “template” for a new app.

It was most recently updated in September 2014, for ASP.NET web app projects that were created with Visual Studio 2013.

.

Using an existing app as a “template” for a new web app

As the complexity of a project increases, you will be interested in using an existing project as a template for your future work. This will lower the effort needed to create a new web app, and improve its quality.

Visual Studio 2013 does not have an easy copy/rename feature to enable you to use a project as a template. Therefore, for now, you can follow this procedure to make a copy of an existing project.

Your first task is to locate the top-level folder of a project that you want to use as a template in the file system. Then:

1. Copy the top-level project folder, and rename the copy as you wish (to a ‘new name’). Then, open the new folder.

2. Inside that folder, change the name of the folder that holds the project files, using the ‘new name’.

3. Change the ‘sln’ (Visual Studio Solution) file name, also using the ‘new name’.

4. Now, edit the ‘sln’ file using Notepad, and edit/update only the name of the folder that holds the project files (leave the other old names there for now). Save and close.

5. Open (double-click) the ‘sln’ in Visual Studio, and make sure the project still builds and runs (it should).

6. Open a class (e.g. in the Models folder). Select the project’s global namespace name, right-click, and choose Refactor > Rename to the ‘new name’. Check-mark all boxes, and proceed (OK, then Apply).

It will also tell you that the project file name will be updated, choose ‘yes’.

7. In Solution Explorer, change (rename) the visible name of the project, to the ‘new name’.

8. Open the project’s properties (Alt+Enter, or right-click Properties). On the “Application” tab, change the assembly name to the ‘new name’.

On the “Web” tab, change the port number in the “Project Url” by adding one to the value. Click “Create Virtual Directory” to save/configure that new value.

Save and close the project’s properties.

9. In Solution Explorer, with the project still selected/highlighted, press Ctrl+H to find-and-replace, search all files in project, replace the old name with the ‘new name’.

10. In Web.config connection strings, check that the database name was changed.

Delete the existing bin and obj folders. And probably the contents of App_Data, depending upon the situation.

Then Build > Clean, and then Build > Rebuild.

.

.

.

.

.

.

.

.

.

.

.

.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

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

%d bloggers like this: