Deploy an ASP.NET Website (Not Web Application) with MSDeploy

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.

MSBuild Differences

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.

https://msdn.microsoft.com/en-us/library/dd547590(v=vs.110).aspx

Create a custom MSDeploy Package

The website folder contains all the files we need to deploy the site to IIS.

image

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.

The Source

If you want to try this for yourself you can clone the source from Github.

https://github.com/rschiefer/WebsiteMSDeployPackage

11 thoughts on “Deploy an ASP.NET Website (Not Web Application) with MSDeploy”

  1. thanks! I’m curious about passing in the contents of the manifest files via command line. I need to be able to build these commands dynamically. Is this pohttps://gravatar.com/site/signup/ssible?

  2. I needed this methodology in order to get web deploy packages working for .net core. This saved me a ton of time so thank you!

  3. Pingback: Package ASP.NET Website (not App) in a CI Build – dotnet catch

  4. As an alternative you can using the following command to auto generate the package through msbuild
    msbuild “” /t:Package /p:PackageLocation=”” /p:OutputPath=””

    1. sorry my place holders had html like tags in them
      msbuild “website project file” /t:Package /p:PackageLocation=”destination folder” /p:OutputPath=”temporary location for publushed websites”

        1. Upon further review I had thought I was using website projects… but turns out I was using web application projects, website projects do not have their own proj files. Please delete my previous comments

          Sorry for the bad information

  5. Thanks for an excellent article.

    I have a question related to the same. I have 10 projects that generate nuget packages. Now I am trying to see if there is way I can create a webdeploy ? Note: I tried creating a empty web app and created packages.config and referred all the 10 nuget packages and did a restore and all that is working but it creates unnecessary files like Roslyn folder all that. Just trying to see if there is a better way.

Leave a Reply to Joe Cancel reply