I’ve never really used the Website project template in Visual Studio but I have heard from several developers that do. Unlike Web Application projects, Microsoft does not provide MSDeploy integration during the build process for Websites. But there is no reason it wouldn’t work. In this blog post we will create a custom MSDeploy package for a Website.
First, if you don’t have a good understanding of WebDeploy/MSDeploy packages you should review my Anatomy of a WebDeploy Package blog post as a primer.
Web Application projects have a project file (.csproj or .vbproj) which controls how the project is built and provides many further features above and beyond the capabilities of a Website. A Website does not require compilation but you can optionally precompile the site if you like.
Because this is optional, it appears Microsoft did not invest in MSDeploy integration for Website builds. This means that creating a MSDeploy package or deploying directly from MSBuild using the following MSBuild arguments will not work:
/P:DeployOnBuild=True /P:DeployTarget=MSDeployPublish /P:MsDeployServiceUrl=https://localhost:8172/msdeploy.axd /P:AllowUntrustedCertificate=True /P:MSDeployPublishMethod=WMSvc /P:CreatePackageOnPublish=True
The following MSDN article provides a more thorough comparison between website and web applications.
Create a custom MSDeploy Package
The website folder contains all the files we need to deploy the site to IIS.
So all we need to do is create a MSDeploy package from this folder.
In this situation, it makes sense to use manifest files because we also want to create the application in IIS. So we will start with manifest.source.xml file:
<?xml version="1.0" encoding="utf-8"?> <sitemanifest> <!--TODO: Update to your custom website location--> <contentPath path="C:\temp\WebsiteMSDeployPackage\WebSite1" /> <createApp path="" /> </sitemanifest>
Here we specify the website directory to be packaged. The createApp provider is simply a placeholder to match the destination manifest.
Next we call MSDeploy to create a package based on the source manifest file.
"c:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:manifest="manifest.source.xml" -dest:package=websitepackage.zip
In order to deploy the package we must have a corresponding manifest.dest.xml file:
<?xml version="1.0" encoding="utf-8"?> <sitemanifest> <!--TODO: Update to your desired application name.--> <contentPath path="Default Web Site/CustomPkgWebsite2" /> <createApp path="Default Web Site/CustomPkgWebsite2" /> </sitemanifest>
Here we are setting the destinations for both the contentPath and createApp to the same IIS web application path. Note in both manifest files you must customize the paths for your application.
Finally, we can deploy our package using MSDeploy.exe using the package for the source and our manifest as the destination:
"c:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package="%cd%\websitepackage.zip" -dest:manifest=manifest.dest.xml
And that’s it, we have successfully deployed a website to IIS.
Other Custom Packages
This same technique should work with any type of IIS hosted application. For example, you could use this to package a PHP web application. Or you could create your own custom packages for a web application with a similar approach instead of using the typical WebDeploy process.
If you want to try this for yourself you can clone the source from Github.