Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Rename Visual Studio Projects and Resolve Related Issues for a Silverlight Application

0.00/5 (No votes)
22 Apr 2012 1  
A step by step guide showing the details of renaming projects and resolving related issues in a Visual Studio 2010 solution for a Silverlight application.

Introduction

The Visual Studio allows us to creating a custom project template for adding a new project based on the settings and references in an existing one. Developers can use this approach to rename a project with related assembly and default namespace when adding a new project. For existing projects in the solution, however, manually changing those names seems more practical and straightforward. The manual renaming tasks are not so hard for an ASP.NET, WPF, or Windows application whereas some special cares are needed for Silverlight web applications. This article provides a guide for how to rename Silverlight projects, reset links between projects due to name changes, and resolve some related issues so that the application will not crash after even extensive name changes.

Let's start with a demo application from my last post which contains both regular Silverlight application projects and WCF RIA Services class library projects. You can download the source code files there and use the solution and projects as the beginning point.

Web Host Server Project

We will change all names related to the web host project from ProductApp.Web to StoreApp.Web.

  1. In the Visual Studio solution, click the ProjectApp.Web project name twice or right-click the project name then select Rename. Change the name text to StoreApp.Web. Renaming a project will automatically change the name of the physical project metadata file (.csproj in C#) and update the reference in any other project in the solution that uses the renamed project.

    1.png

  2. Make sure that the StoreApp.Web is selected as the current project. Open the Quick Replace screen by clicking Find and Replace from the Edit menu. Replace all instances of ProductApp.Web with StoreApp.Web in code files for the current project.

    2.png

  3. Right-click the project name, select Properties, and then select Application side menu. Change the current text in both Assembly name and Default namespace field to StoreApp.Web. We will keep the name of assembly and default namespace the same as that of the project for the clarity and easy maintenance although these names can be different.

    3.png

  4. Click Show All Files icon in the Solution Explorer, and delete the ProductApp.Web.dll and ProductApp.Web.pdb in the bin folder. Alternatively we can delete the bin folder if there is no manually entered library source file inside and let build process repopulate it. This step is not required but doing so will keep the project clean.

    4.png

  5. Save all files by pressing Ctrl + Shift + S keys and then clicking the Close Solution command in the File menu to close the solution.

    Special Note: making sure to close the solution when renaming the physical project location folder and doing solution or project metadata file content changes outside the Visual Studio in below steps.

  6. Go to the physical root folder of the solution using the Windows Explorer, rename the folder ProductApp.Web to StoreApp.Web under the solution root folder.

  7. Open the ProductApp.sln file using the Notepad or any other text editor. Find the lines shown below.

    Project("{-GUID number-}") = "StoreApp.Web", "ProductApp.Web\StoreApp.Web.csproj", "{-GUID number-}"
    EndProject

    Change the relative directory path from ProductApp.Web to StoreApp.Web in the code and then save the file.

    Project("{-GUID number-}") = "StoreApp.Web", "StoreApp.Web\StoreApp.Web.csproj", "{-GUID number-}"
    EndProject
  8. Re-open the solution by selecting the ProductApp.sln from the Recent Projects and Solutions of the File menu. The application should work fine when running it by pressing F5.

Silverlight Client Project

We will change all names related to main client project from ProductApp to StoreApp.Main. There are more steps involved in the renaming and associated issues for this type of projects than any other types.

  1. In the Solution Explorer, change the project name ProductApp to StoreApp.Main using the same step shown for the web host project.

  2. Make sure that the StoreApp.Main is selected as the current project. Use the Quick Replace screen to replace all instances of ProductApp with StoreApp.Main in code files for the current project.

    5.png

  3. Right-click the project name, select Properties, and then select Silverlight side menu. Perform the following changes.

    • Rename the current text in the Assembly name filed to StoreApp.Main
    • Rename the current text in the Default namespace to StoreApp.Main
    • Select the updated StoreApp.Main.App in the Starup object dropdown list
    • Change from ProductApp.xap to StoreApp.Main.xap in the Xap file name field

    The updated Properties screen should look like this:

    6.png

  4. In the Show All Files mode, delete the Debug folder under the bin folder if there is no manually entered library source file inside. Otherwise, just delete the old ProductApp.dll, ProductApp.pdb, ProductApp.xap, and ProductAppTestPage.html. Again this step is optional.

  5. Expend the obj folder and delete the Debug folder under it. The Visual Studio will re-populate the Debug folder during next build process. This is a very important step. If missing this step, the changed assembly name will not be in effect because the cached files for the assembly in the obj\Debug folder are not refreshed. We will get runtime errors or the data binding failure. Restarting the development web server or IIS, or re-opening the Visual studio would not help. This behavior is for the Silverlight projects only (both for C# and VB), not for all other types such as ASP.NET, WPF, or Windows projects.

    7.png

  6. Save all files and close the solution (see the special note previously for modifying physical project folder name and metadata file contents).

  7. Go to the physical root folder of the solution using the Windows Explorer, rename the folder ProductApp to StoreApp.Main under the root solution folder.

  8. Open the ProductApp.sln file using the Notepad or any other text editor. Find the lines shown below.

    Project("{-GUID number-}") "StoreApp.Main", "ProductApp\StoreApp.Main.csproj", "{-GUID number-}"
    EndProject

    Change the relative directory path from ProductApp to StoreApp.Main in the code and then save the file.

    Project("{-GUID number-}") "StoreApp.Main", "StoreApp.Main\StoreApp.Main.csproj", "{-GUID number-}"
    EndProject
  9. Still in the Windows Explorer, open the StoreApp.Main.csproj project file under StoreApp.Main folder. Find the line:

    <TestPageFileName>ProductAppTestPage.html</TestPageFileName>

    Change the ProductAppTestPage.html to StoreAppMain.html in the code and then save the file.

    <TestPageFileName>StoreAppMain.html</TestPageFileName>
  10. Re-open the solution. In the web server StoreApp.Web project, rename the ProductAppTestPage.aspx to StoreAppMain.aspx and ProductAppTestPage.html to StoreAppMain.html. See the screenshot under the Step 12.

  11. Since the link exists between the web and client projects, the server will automatically update the xap file name when the name is changed from the client project. However, the xap file name in the starting page files is not updated. We need to open both StoreAppMain.aspx and StoreAppMain.html files and then find first param node under the object node. Change the xap file name from ProductApp.xap to StoreApp.Main.xap in the code. The updated code is shown below.

    <param name="source" value="ClientBin/StoreApp.Main.xap"/>
  12. The old ProductApp.xap in the ClientBin folder will not be used. We can delete it.

    8.png

  13. In the Solution Explorer, right-click the StoreAppMain.aspx and select Set As Start Page. The application should work fine when running it by pressing F5.

RIA Services Class Library Server Project

We will change all names related to the RIA Services server project from ProductRiaLib.Web to StoreRiaLib.Web. The steps for renaming the RIA Services Class Library server project are similar to those for the Web host server project. Refer to the corresponding screenshots if needed.

  1. Rename the ProductRiaLib.Web to StoreRiaLib.Web in the Solution Explorer. This will automatically change the physical project metadata file name and update the project reference set in the web host server project, the StoreApp.Web.

  2. Make sure that the StoreRiaLib.Web is selected as the current project. Use the Quick Replace screen to replace all instances of ProductRiaLib.Web with StoreRiaLib.Web in code files for the current project.

  3. In the Application section of the project Properties screen, change the existing text in both Assembly name and Default namespace fields to StoreRiaLib.Web.

  4. Delete the ProductRiaLib.Web.dll and ProductRiaLib.Web.pdb in the bin folder to keep the project clean.

  5. Save all files and close the solution (see the special note previously for modifying physical project folder name and metadata file contents).

  6. Go to the physical root folder of the solution using the Windows Explorer, rename the folder ProductRiaLib.Web to StoreRiaLib.Web under the root solution folder.

  7. Open the ProductApp.sln file using the Notepad or any other text editor. Find the lines shown below.

    Project("{-GUID number-}") = "StoreRiaLib.Web", "ProductRiaLib.Web\StoreRiaLib.Web.csproj", "{-GUID number-}"
    EndProject

    Change the relative directory path from ProductRiaLib.Web to StoreRiaLib.Web in the code and then save the file.

    Project("{-GUID number-}") = "StoreRiaLib.Web", "StoreRiaLib.Web\ StoreRiaLib.Web.csproj", "{-GUID number-}"
    EndProject
  8. Re-open the solution but do not build or run the application until completing the changes in the RIA Services class library client project performed in the next section.

    9.png

  9. If the database file is in the App_Data folder in this project and the absolute path is used in the connection string, a change is needed for the connection string in the Web.config file from the web host server project, in our case, the StoreApp.Web project. Change ProductRiaLib.Web to StoreRiaLib.Web for the Data Source of the connection string.

    <connectionStrings>    
        <add name="ProductDbContext" connectionString="Data Source=[Your-StoreApp-Solution-Path]\StoreRiaLib.Web\App_Data\ProductData.sdf" providerName="System.Data.SqlServerCe.4.0"/>
    </connectionStrings>

RIA Services Class Library Client Project

We will change all names related to the RIA Service client project from ProductRiaLib to StoreRiaLib.Client. In addition to the similar steps that are used for the RIA Services class library server project, some other interventions are needed.

  1. Rename the ProductRiaLib to StoreRiaLib.Client in the Visual Studio Solution Explorer. This will automatically change the physical project metadata file name and update the project reference set in the Silverlight client project, the StoreApp.Main.

  2. Make sure that the StoreRiaLib.Client is selected as the current project. Use the Quick Replace screen to replace all instances of ProductRiaLib with StoreRiaLib.Client in the code for the current project.

  3. Right-click the project name, select Properties, and then select Silverlight side menu. Perform the following changes.

    • Rename the current text in the Assembly name filed to StoreRiaLib.Client
    • Rename the current text in the Default namespace to StoreRiaLib.Client
    • Select the updated StoreRiaLib.Web in the WCF RIA Services link dropdown list

    The updated Properties screen should look like this:

    10.png

  4. Delete the ProductRiaLib.Web.dll and ProductRiaLib.Web.pdb in the bin folder to keep the project clean.

  5. Save all files and close the solution (see the special note previously for modifying physical project folder name and metadata file contents).

  6. Go to the physical root folder of the solution using the Windows Explorer, rename the folder ProductRiaLib.Web to StoreRiaLib.Web in the root solution folder.

  7. Open the ProductApp.sln file using the Notepad or any other text editor. Find the lines shown below.

    Project("{-GUID number-}") = "StoreRiaLib.Client ", "ProductRiaLib\StoreRiaLib.Client.csproj", "{-GUID number-}"
    -some other nodes-
    EndProject

    Change the relative directory path from ProductRiaLib.Web to StoreRiaLib.Web in the code and then save the file.

    Project("{-GUID number-}") = "StoreRiaLib.Client ", "StoreRiaLib.Client\StoreRiaLib.Client.csproj", "{-GUID number-}"
    -some other nodes-
    EndProject
  8. Open the StoreRiaLib.Client.csproj file under the project folder StoreRiaLib.Client using the Notepad or any other text editor. Find if the LinkedServerProject node points to the correct physical server location. If not, update it with the correct one shown below.

    <LinkedServerProject>..\StoreRiaLib.Web\StoreRiaLib.Web.csproj</LinkedServerProject>
  9. Re-open the solution.

  10. Before building or running the application, we need to replace the old RIA Serives namespace references with the new ones in all Silverlight client projects that consume the RIA Services. The data is always provided in the namespace of RIA Services Server project, in our updated case, the StoreRiaLib.Web although the code from the client proxy file in the RIA Services client project is actually accessed. Select the StoreApp.Main project as the current project and replace all instances of ProductRiaLib.Web with StoreRiaLib.Web in code files using the Quick Replace screen.

    11.png

    Note that the principle of this step applies to any case when the namespace is changed for a class library project referenced by a consumer project. For example, if we have the ProductApp.Common class library with the same name for the namespace, when renaming the project and namespace to StoreApp.Common, the namespace references or prefixes for all projects using this library need to be changed to StoreApp.Common in the code.

  11. Run the application by pressing F5. The application should work as the same as before all projects are renamed.

What Else?

So far all the functional parts are renamed and work well. However the solution name, solution physical filename, and the names of virtual solution folders, if any, inside the solution are still old.

12.png

Renaming the solution and solution virtual folder can be easily done by directly changing the name text in the Solution Explorer. The solution physical file name will automatically be updated when renaming the solution. Renaming a virtual solution folder name is entirely independent from other parts of the solution.

All final names for the demo application are shown like this.

13.png

Summary

Renaming projects and resetting related issues for a Silverlight application are not so easy. Architects and developers need well plan all the names for projects to avoid making name-related changes. But in case you need to rename your projects in the development phases, or for project expansions, or importing projects from other resources but having naming issues, you can freely do the renaming tasks following this guide.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here