powershell - 如何仅在 VS 2012 中的 Web 部署发布任务之前执行 PowerShell 脚本?

标签 powershell visual-studio-2012 publish msdeploy post-build-event

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

enter image description here

这基本上称为 PowerShell script向每个 .cs 文件添加版权声明。

我想要做的是仅在将网络应用程序发布到远程服务器之前执行此powershell脚本。这样做我每次需要调试项目时都不会遇到延迟。您知道有什么方法可以实现这一目标吗?

<小时/>

根据Sayed's answer ,我定制了一个特定的发布配置文件并添加了以下内容:

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

最佳答案

这取决于您之前如何定义,但下面是一种技术。

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

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

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

仅供引用,关于 .wpp.targets 的定制,这是我们在 VS2010 中拥有的唯一技术。我的建议如下;在大多数情况下自定义 .pubxml 文件,并且仅在您想要自定义给定项目的每个发布时才创建 .wpp.targets 文件。

关于powershell - 如何仅在 VS 2012 中的 Web 部署发布任务之前执行 PowerShell 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12907236/

相关文章:

.net - 匹配不以 [ 且不以 ] 结尾的行的正则表达式(ini header )

xml - 如何将 .xml 读入内存并写出相同的结果

在另一个类中发送的 c# 数组发回零

python - 在当前进程中通过 python 运行 bat 文件

android - APK "Publish Now"定时 Release模式

javascript - 批量删除%LOCALAPPDATA%中的文件夹

powershell - 从格式为 "HH:mm:ss,fff"的字符串计算总秒数

c++ - 模板参数推导失败,使用函数指针作为参数

google-apps-script - 找不到 Google 云端硬盘页面 - 抱歉,目前无法打开文件

asp.net - 无法从浏览器访问IIS中发布的Asp.net网站