Automatically deploy a LightSwitch-ready hosting website with ability to set the https certificate.


My previous post covered an end-to-end approach for deploying a Lightswitch-ready application pool. We’ll try in this post to do the same for an hosting website (in which you can deploy a LightSwitch application)


Create a Pre-Template website



Change the standard http binding to port 1 and select a physical path:


Make sure you have a server certificate installed on your IIS which you will use for actual web sites. On the other hand, for this preparation step, we need a dummy certificate (can be a self-signed one).

So, if you consult the certificate window in your IIS, you should have:

Create an https binding and attach the dummyCertificate to the port. The portnumber should be set to 2.


So, this gives:



Export now this site as a server package:


Select as follows:


Save the package to “PreTemplateWebSitePackage” en provide a password when asked.


Massage the pre template website package to a template website package

First create an xml file named “” with following content:

  <!-- declare parameter for Http Binding -->
  <parameter name="Site-http" description="Site Http Binding">
    <parameterEntry kind="DestinationBinding" scope="Site" match=":1:" />
 <parameter name="Site-https" description="Site Https Binding">
    <parameterEntry kind="DestinationBinding" scope="Site" match=":2:" />
  <parameter name="Application Pool" description="app pool">
    <parameterEntry kind="DeploymentObjectAttribute" scope="appHostConfig" match="application/@applicationPool" />


Run now following command file (make sure msdeploy is in your path environment settings):

SET PreTemplateWebSitePackage=""
SET TemplateWebSitePackage=""
SET DeclareParametersFile="DeclareWebSiteParameters.xml"
SET WebDeployFullPath="C:\Program Files\IIS\Microsoft Web Deploy V3\"

cd D:\Deploy\WebSiteManagement
%WebDeployFullPath%msdeploy.exe -verb:sync -source:package=%PreTemplateWebSitePackage%,encryptpassword="secret" -dest:package=%TemplateWebSitePackage%,encryptpassword="secret" -declareParamFile:%DeclareParametersFile%



Ok, we have now our template website package !


Create a new website based on our template package and update also the ssl certificate

Create a new xml file called “WebSiteParameters”

  <setParameter name="Site-http" value="*:101:"/>
  <setParameter name="Site-https" value="*:1010:"/>
  <setParameter name="Application Pool" value="MyNewAppPool"/>

As you can see, these parameters will update the http en https port and sets the application pool. There is nothing in this parameter file to update the certificate.


Following command will deploy the web site:

SET _siteName="NEWSITE"
SET _destinationWebSitePhysicalPath="C:\inetpub\NEWSITE"
SET _computeName="localhost"
SET TemplateWebSitePackage=""
SET TemplateWebSitePackage=""
SET ParametersFile="WebSiteParameters.xml"
SET WebDeployFullPath="C:\Program Files\IIS\Microsoft Web Deploy V3\"
SET _dummyPassword="secret"
SET _httpsSiteCertificate="ee05abbcbb462f1825cdfa39ed37aa96e06687b1"

cd D:\Deploy\WebSiteManagement
%WebDeployFullPath%msdeploy  -verb:sync -source:package=%TemplateWebSitePackage%,encryptpassword=%_dummyPassword% -dest:appHostConfig=%_siteName%,computerName=%_computeName% -setParamFile=%ParametersFile% -replace:objectName=virtualDirectory,targetAttributeName=physicalPath,match="^C:\\inetpub\\PreTemplateWebSite",replace=%_destinationWebSitePhysicalPath% -replace:objectName=httpCert,targetAttributeName=hash,replace=%_httpsSiteCertificate%


Playing around with ssl certificate is not an issue any longer :)