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.
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.

- 43,864
- 17
- 144
- 178
-
2This doesn't work. There is a circular dependency involving target "Build". (Package call Build, Build call Package...) – Julien Hoarau Jul 01 '10 at 14:58
-
error MSB4006: There is a circular dependency in the target dependency graph involving target "Build". – Julien Hoarau Jul 01 '10 at 15:50
-
-
First I got the circular dependency error, but changing Package to CreatePackage solved the problem. – Apr 08 '11 at 08:11
-
6I got the circular dependency (but only when building from command line, not inside VS). "CreatePackage" did not work (target does not exist). In order to get a package as part of every build I changed my DefaultTargets of the Project element to be "Build;Package" which would seem to address Sayed's concern about not packaging during build (from within VS) yet support producing a Package as part of a command line build – Peter McEvoy May 10 '11 at 13:01
-
Am I correct in understanding that this will either work in VS builds *or* work with MSBuild, but not both? Is there any solution that will work for both? – Micah Zoltu Apr 06 '15 at 22:14
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)"/>

- 36,600
- 15
- 168
- 198
website1
websiteDeployment
sqlScripts
website2
websiteDeployment
sqlScripts
– Vadim Rybak Jul 01 '10 at 15:53