如何仅在VS 2012中的Web部署发布任务之前执行PowerShell脚本? [英] How to execute a PowerShell script only before a web deploy Publish task in VS 2012?

查看:96
本文介绍了如何仅在VS 2012中的Web部署发布任务之前执行PowerShell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我在Web项目中使用Visual Studio 2012配置了一个构建后事件,如下所示:

Currently I have a post-build event configured in my web project using Visual Studio 2012 like this:

这基本上会调用 PowerShell脚本,以向每个.cs文件添加版权声明.

This basically calls a PowerShell script to add a copyright notice to every .cs file.

我想做的是仅在将Web应用发布到远程服务器之前执行 这个Powershell脚本.这样一来,我每次调试项目时都不会遇到延迟.您知道实现此目的的任何方式吗?

What I'd like to do is to execute this powershell script only before Publishing the web app to the remote server. Doing so I won't experience a delay every time I need to debug the project. Do you know of any way of accomplishing this?

根据说出的答案,我自定义了一个特定的发布配置文件并添加了以下内容:

According to Sayed's answer, I customized a specific publish profile and added this:

<PipelineDependsOn>
  CustomBeforePublish;
  $(PipelineDependsOn);
</PipelineDependsOn>
</PropertyGroup>
<Target Name="CustomBeforePublish">
<Message Text="******* CustomBeforePublish *******" Importance="high" />
<Exec Command="powershell.exe -file &quot;$(ProjectDir)\Copyright.ps1&quot;" />
</Target>

推荐答案

这取决于您之前定义的方式,而下面是一种技术.

It depends on how you define before but below is one technique.

使用VS2012创建发布配置文件时,它将在Properties \ PublishProfiles文件夹( VB的My Project \ PublishProfiles )中创建一个.pubxml文件.这些是MSBuild文件,您可以编辑它们以自定义发布过程.在您的情况下,您可以在实际发生发布之前将目标注入到发布过程中.您可以通过如下扩展PipelineDependsOn属性来做到这一点.

When you create a publish profile with VS2012 it will create you a .pubxml file in the Properties\PublishProfiles folder (My Project\PublishProfiles for VB). These are MSBuild files and you can edit them to customize the publish process. In your case you can inject a target into the publish process, before the publish actually occurs. You can do that by extending the PipelineDependsOn property as below.

<PropertyGroup>
  <PipelineDependsOn>
    CustomBeforePublish;
    $(PipelineDependsOn);
  </PipelineDependsOn>
</PropertyGroup>

<Target Name="CustomBeforePublish">
  <Message Text="********************************** CustomBeforePublish ***********************************" Importance="high"/>
</Target>

仅供参考,关于.wpp.targets的自定义,这是我们针对VS2010的唯一技术.我的建议如下:在大多数情况下,请自定义.pubxml文件,并且仅在要自定义给定项目的每个发布时才创建.wpp.targets文件.

FYI regarding the customization of .wpp.targets, that was the only technique which we had for VS2010. My recommendation here is as follows; customize the .pubxml file for most cases and to only create a .wpp.targets file if you want to customize every publish of the given project.

这篇关于如何仅在VS 2012中的Web部署发布任务之前执行PowerShell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆