【发布时间】:2017-07-06 13:22:30
【问题描述】:
我想在发布到本地文件夹之前运行 gulp 任务。所以尝试使用“BeforePublish”目标,但它不能正常工作。我做错了什么吗?
<Target Name="BeforePublish">
<Message Text="Before publish triggered...."></Message>
</Target>
【问题讨论】:
标签: visual-studio msbuild
我想在发布到本地文件夹之前运行 gulp 任务。所以尝试使用“BeforePublish”目标,但它不能正常工作。我做错了什么吗?
<Target Name="BeforePublish">
<Message Text="Before publish triggered...."></Message>
</Target>
【问题讨论】:
标签: visual-studio msbuild
我用的是VS2017。我可以使用 MSbuild.exe 在命令提示符中获取文本。
所以请确保您正确编辑 .xxproj 文件,并在您身边正确运行 msbuild 命令行。我只是使用一个简单的 Winform 应用程序对其进行测试。
更新:
如果您只想在使用 VS IDE 发布期间调用它,我认为您可以在此处获得解决方法:
How to execute a PowerShell script only before a web deploy Publish task in VS 2012?
【讨论】:
经过几个小时的战斗,我想我想出了非常简单且通用的解决方案。我发现没有一个解决方案对我有用(“发布”目标仅适用于 ClickOnce),所以我想出了这个:
发布文件 (pubxml) 只是类似项目的文件。所以添加一些值,例如:
<IsPublish>True</IsPublish>
然后在项目文件中:
<Target Name="MessageBeforePublish" AfterTargets="Build" Condition="'$(IsPublish)' == 'True'">
<Message Text="Before publishing..." Importance="high" />
</Target>
所以,明确地说,我的 pubxml 文件如下所示:
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration>Release</Configuration>
<Platform>x64</Platform>
<PublishDir>***my dir***</PublishDir>
<PublishProtocol>FileSystem</PublishProtocol>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<PublishSingleFile>False</PublishSingleFile>
<PublishReadyToRun>True</PublishReadyToRun>
<PublishTrimmed>False</PublishTrimmed>
<IsPublish>True</IsPublish>
</PropertyGroup>
</Project>
请注意我添加的最后一个属性 (IsPublish)。 就是这样。
【讨论】: