将网站部署包构建为构建后事件

发布于 2024-09-07 15:30:01 字数 122 浏览 7 评论 0原文

我正在使用 Visual Studio 2010。我有一个网站项目,我想在每次构建项目时构建一个网站部署包。基本上,我正在寻找构建后 MSBuild 命令的一些示例,该命令基本上与网站右键菜单中的“构建部署包”选项执行相同的操作。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榆西 2024-09-14 15:30:01

我假设您正在使用 Web 应用程序项目,因为网站项目没有“构建部署包”。

我建议不要在每个构建上执行包,因为这会大大减慢您的开发速度。话虽这么说,你可以在这里做到这一点。

如果您确实想要执行此操作,那么最好的选择不是使用构建后事件,而是编辑项目文件并扩展构建过程。为此,请打开您网站的 .csproj 文件,然后在底部(在导入元素之后)放置以下内容。

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

这样做的作用是扩展构建过程以调用 目标。这与在 Visual Studio 中调用“构建部署包”目标时调用的目标相同。

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.

浅黛梨妆こ 2024-09-14 15:30:01

对我来说,Sayed 的答案不适用于命令行 msbuild 执行(我需要 Publish target,但思路是一样的):

目标依赖图中存在循环依赖
涉及目标“构建”

我无法使用 DefaultTargets 因为我想在命令行上发布但只能从 VS 构建。这是有效的:

<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)"/>

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)"/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文