Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build website deployment package as a postbuild event

I am using visual studio 2010. I have a website project that I would like to build a website deployment package every time I build a the project. Basically I am looking for some example of a post build MSBuild command that will basically do the same thing as the "Build Deployment Package" option from the right click menu of the website.

like image 669
Vadim Rybak Avatar asked Nov 30 '25 06:11

Vadim Rybak


2 Answers

I assume you are using Web Application Projects, because Web Site projects do not have the "Build Deployment Package".

I would recommend not performing a package on every build, because it will slow down your development drastically. With that being said, you can do it here is how.

If you really wanted to do this your best bet is not to use post-build event, but to edit the project file and extend the build process. To do this open the .csproj file for your web and then towards the bottom (after the Import elements) place the following

<PropertyGroup>
  <BuildDependsOn>
    $(BuildDependsOn);
    Package
  </BuildDependsOn>
</PropertyGroup>

What this does is extend the build process to call the Package target. This is the same target that is called when you invoke the "Build Deployment Package" target in Visual Studio.

like image 51
Sayed Ibrahim Hashimi Avatar answered Dec 04 '25 14:12

Sayed Ibrahim Hashimi


For me, Sayed's answer didn't work with a command-line msbuild execution (I needed the Publish target, but the idea is the same):

There is a circular dependency in the target dependency graph involving target "Build"

I couldn't use DefaultTargets because I wanted to publish on the command-line but only build from VS. Here's what did work:

<Project 
      ToolsVersion="12.0" 
      DefaultTargets="BuildAndOrPublish" 
      xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
      <BuildAndOrPublishDependsOn Condition=" '$(BuildingInsideVisualStudio)' == 'true' ">
        Build
      </BuildAndOrPublishDependsOn>  
      <BuildAndOrPublishDependsOn Condition=" '$(BuildingInsideVisualStudio)' != 'true' ">
        Publish
      </BuildAndOrPublishDependsOn>  
  </PropertyGroup>

  <Target Name="BuildAndOrPublish" DependsOnTargets="$(BuildAndOrPublishDependsOn)"/>
like image 40
Ohad Schneider Avatar answered Dec 04 '25 14:12

Ohad Schneider



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!