目前,我使用 Visual Studio 2012 在我的 Web 项目中配置了一个构建后事件,如下所示:
这基本上称为 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 "$(ProjectDir)\Copyright.ps1"" />
</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/