Web development environment scripting

Sometimes getting a web project running on your development machine requires a lot more work than simply doing a

Inspired by my colleagues Anders Janmyr, who wrote the book (or at least a great blog post) on being a responsible developer, and with the help of Morten Faester, who has done a tremendous job on scripting the development environment on a recent project, this blog post will describe how to script a complete development environment for a .NET web project from the command line.

The following steps are described:

  • Prerequisites
    – Installing via web platform installer and DISM
  • IIS
    – IIS app pool
    – IIS website
  • SSL certificate
    – import SSL certificate
  • hosts file
    – Add entry in hosts file
  • SQL Server
    – Create database
    – Setup access rights for the IIS app pool

Most of these commands are pretty self-explanatory, I will simply show the commands needed to setup  an environment for a project called “scriptingdemo”, running locally on the url http(s)://scriptingdemo/ with access to a sql server database also called scriptingdemo.

The install scripts need to be run from a command prompt with administrative privileges.

Install prerequisites

It might be necessary to ensure certain windows components are installed (such as IIS management console). Other dependencies, that are not windows components can be installed via Web Platform Installer (which you need to download and install separately).

Installing windows components can be done with the following command

A complete list of features can be retrieved with:

For this project we would like to ensure IIS and its components are installed.

 

You can script installation of software via web platform installer like this:

Where <productid> indicates what you want to install. You can get a list of already installed products using the command

Or a list of products available for installation

For this project we would like to make sure we have SQL Express with tools and .NET 4.5 installed.

IIS

This script will create a website in IIS with its own app pool:

SSL certificate

Our local site is set up to run both http and https. To establish a secure connection via https, we a self-signed ssl-certificate for the url https://scriptingdemo/. Generating this certificate is only done once and then the certificate is distributed in the source code along with the setup script files. I’m showing the command here anyway:

The -n option is where you specify the hostname for the certificate.

Once we have the certificate, you can export it from your certificate store:

  • Start mmc.exe
  • File => Add/Remove Snap-in
  • Add a certificate snap-in for local computer
  • Go to “Certificates (local computer)” => Personal => Certificates and right click on the scriptingdemo certificate
  • All tasks => export (export the certificate to a file called scriptingdemo.pfx
  • Take the exported certificate and put it next to the setup script files.

At this point you might want to remove the certificate from you certificate store, so you can verify if the script adding the certificate works.

The next step is to import the certificate (-p option is the password you provided when the certificate was exported) and finally we bind the imported certificate to the site running on https://scriptingdemo

The parameter certhash identifies the certificate and can be found if you open the certificate from the certificate snap-in and look for Thumbprint under the details tab. The parameter appid is just any unique guid.

SQL Server

This script will run the content of a sql-script file against the local sqlexpress instance.

This is the content of the file makedb.sql, which will create a sql server database for our website and set the AppPool running the site as db_owner.

If your web application does  not automatically bootstrap itself on startup, you need to run the sql script needed to setup the data as well.

 hosts file

This script will insert an entry in the hosts file, pointing the url http(s)://scriptingdemo/ to the localhost

 

This Post Has 3 Comments

  1. It’s a good technique as well as its help web designer.

  2. I do web developing in php and some times i found it difficult to overcome the errors in my code. the way you have explained here about the scripting in web developing is very authentic and useful to all programmers. I really had a good time in visiting your site. I have tried your code it really works well.

Leave a Reply

Close Menu