目前,我使用Visual Studio 2012在我的web项目中配置了一个构建后事件,如下所示:
这基本上调用了一个PowerShell script来为每个.cs文件添加版权声明。
我想要做的是在将web应用程序发布到远程服务器之前执行这个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>
发布于 2012-10-17 01:45:31
这取决于您之前是如何定义的,但下面是一种技术。
当您使用VS2012创建发布配置文件时,它会在属性\发布配置文件文件夹(我的项目\VB的发布配置文件)中创建一个.pubxml文件。这些是MSBuild文件,您可以对其进行编辑以自定义发布过程。在本例中,您可以在发布实际发生之前将目标注入到发布过程中。您可以通过扩展PipelineDependsOn属性来实现,如下所示。
<PropertyGroup>
<PipelineDependsOn>
CustomBeforePublish;
$(PipelineDependsOn);
</PipelineDependsOn>
</PropertyGroup>
<Target Name="CustomBeforePublish">
<Message Text="********************************** CustomBeforePublish ***********************************" Importance="high"/>
</Target>
仅供参考,关于.wpp.targets的自定义,这是我们为VS2010提供的唯一技术。我的建议如下:在大多数情况下自定义.pubxml文件,如果您想自定义给定项目的每次发布,则只创建一个.wpp.targets文件。
发布于 2018-07-27 17:59:00
Sayed
的答案解决了这个问题。然而,我想提供一个完全有效的答案(在Visual Studio2017中测试):
<PropertyGroup>
<PipelineDependsOn>
PreBuildScript;
$(PipelineDependsOn);
</PipelineDependsOn>
</PropertyGroup>
<Target Name="PreBuildScript">
<Message Text="Executing prebuild script" Importance="high"/>
<Exec Command="powershell.exe -file "$(ProjectDir)\InnerFolder\script.ps1"" />
</Target>
注意:这将在预览和实际发布操作中执行,因此可以在实际发布之前找出发布前的错误。
发布于 2012-10-16 13:54:28
在web应用程序的根目录中声明以下ProjectName.wpp.targets
文件:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BeforeAddContentPathToSourceManifest>
$(BeforeAddContentPathToSourceManifest);
AddCopyright;
</BeforeAddContentPathToSourceManifest>
</PropertyGroup>
<Target Name="AddCopyright">
<!-- I recommend passing in $(_MSDeployDirPath_FullPath) to your script
as the base path to search to avoid having to perform a VCS rollback
(files are copied there before the deployment)
-->
<Exec Command="powershell.exe -file "$(SolutionDir)Copyright.ps1" "$(_MSDeployDirPath_FullPath)"" />
</Target>
</Project>
https://stackoverflow.com/questions/12907236
复制相似问题