Build website deployment package as a postbuild ev

2020-03-06 03:04发布

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条回答
欢心
2楼-- · 2020-03-06 03:08

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-03-06 03:30

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)"/>
查看更多
登录 后发表回答