In all project it’s a real nightmare to manage configuration files. In Silverlight projects like in web applications, you can take advantage of Web Application Project Deployment features of Visual Studio 2010. In this blog, I’ll explain you :
- How to create a new configuration (part 1);
- How to create package definition (part 1);
- How to create package (part 1);
- How to publish the application (part 1);
- How to use transformation with web.config files (part 2);
- Some more links on this subject (part 2).
In this post, I won’t explain SQL deployment.
Creation of a new solution configuration
Right click on your solution file in Visual Studio, select Properties, on the left tree view, select configuration.
After clicking on the button “Configuration Manager …”, another pop-up appears. In the left drop down list, select “<New …>”. The “<Edit …>” button is used to rename or remove a configuration.
In the new pop-up, enter the name of the desired new configuration. In this case, “Staging”. You can use the “Copy settings from:” to duplicate settings from a specific configuration.
By default, the selected configuration is the one just created (i.e. Staging).
To make appears the dedicated web.config in the web application, right click on the web.config and select “Add Config Transforms”, and the Web.Staging.config will be created.
How to create the package definition
Right click on the web project and select “Properties”. Select “Package/Publish” tab.
This screen is used to configure you deployment. You can specifies what you really want to package : pdb files, App_Data folder, database, …
For Silverlight application, “Only files needed to run this application” in the Items to deploy drop down list also deploys xap files.
Than, you can define the Web Deployment Package settings.
How to create the package
Rebuild your application to view the resulting package, right click on the web application and select “Create Package”.
As in previous paragraph, we have kept the default settings, you can see that in the obj folder, Visual Studio has created a new folder named Staging with a lot of files.
A zip file (folder obj/Staging/Package) named like your web project is present. This files contains :
- Configuration files used for deployment;
- The code to deploy.
In the same folder, a cmd file is present.
How to publish the application
To deploy the package there is several way:
- Import the package with IIS Manager (http://learn.iis.net/page.aspx/515/import-a-package-through-iis-manager/);
- Using the cmd file that is present in the package folder;
- Use Visual Studio “Publish …” (right click on the web project) function. It provides file system, MSDeploy, FTP and FPSE publish mechanism.
Visual Studio provides easy to use screens for deployment. Using Profiles is very great to store all publication locations depending on your server.
In this sample, I used a file system deployment on the c:\temp folder.