← back to the blog


Deploy Asp.net Web App

Posted in Visual Studio, ASP.NET by dake

Few tips for deploy aspnet web application

For a enterprise ASP.NET web application scenarios please reference following documents.

Deploying Web Applications in Enterprise Scenarios

Understanding the Project File

Deployment made simple using Powershell

During the application build or deploy if you have anything need to be include but not checked-in to the project, you can try following command.

Following is example command that during the project build it will copy files or folder to sepecific location depend on you are on local or deploy. If you use powershell to write your own deployment scripts following project, csproj code will copy the files or folder, which you don't need to write that to powershell.

<Target Name="AfterBuild">
    <ItemGroup>
      <DefinedTargetFolder Include="$(SolutionDir)\AllFilesFolder\**\*.*" />
    </ItemGroup>
    <!-- for local -->
    <Copy Condition="$(IsDesktopBuild)=='true' Or $(IsDesktopBuild)==''" SourceFiles="@(DefinedTargetFolder)" DestinationFolder="$(SolutionDir)\YourTargetFolderDuringLocalBuild\%(RecursiveDir)" />
    <!-- for deploy to tfs-->
    <Copy Condition="$(IsDesktopBuild)=='false'" SourceFiles="@(DefinedTargetFolder)" DestinationFolder="$(OutDir)\YourTargetFolderDuringTfsMSBuildOrDeploy\%(RecursiveDir)" />   
  </Target>

Example.pubxml

Following is almost same thing like previous code is doing, however it will use project pubxml.


<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>YourConfigurationName</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>C:\YourLocalFolder</publishUrl>
    <DeleteExistingFiles>False</DeleteExistingFiles>
  </PropertyGroup>
  <Target Name="copyAdditionalFilesOrFolderForDeploy">
    <ItemGroup>     
      <_CustomFiles Include="$(MSBuildProjectDirectory)\TargetFolder\**\*" />
      <FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
        <DestinationRelativePath>TargetFolder\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
      </FilesForPackagingFromProject>
    </ItemGroup>
  </Target>
  <PropertyGroup>
    <CopyAllFilesToSingleFolderForPackageDependsOn>copyAdditionalFilesOrFolderForDeploy;;</CopyAllFilesToSingleFolderForPackageDependsOn>
  </PropertyGroup>
</Project>

Powershell Gallery

What's next?

For deployment, should use visual studio 2015's DevOps deployment tools.