【问题标题】:Visual studio before publish target is not triggering发布目标前的 Visual Studio 未触发
【发布时间】:2017-07-06 13:22:30
【问题描述】:

我想在发布到本地文件夹之前运行 gulp 任务。所以尝试使用“BeforePublish”目标,但它不能正常工作。我做错了什么吗?

<Target Name="BeforePublish">
    <Message Text="Before publish triggered...."></Message>
  </Target>

【问题讨论】:

    标签: visual-studio msbuild


    【解决方案1】:

    我用的是VS2017。我可以使用 MSbuild.exe 在命令提示符中获取文本。

    所以请确保您正确编辑 .xxproj 文件,并在您身边正确运行 msbuild 命令行。我只是使用一个简单的 Winform 应用程序对其进行测试。

    更新:

    如果您只想在使用 VS IDE 发布期间调用它,我认为您可以在此处获得解决方法:

    How to execute a PowerShell script only before a web deploy Publish task in VS 2012?

    【讨论】:

    • 其实我希望在我右键发布我的web项目时触发它
    • @Jaffer Sathick,我只是提供了使用 MSbuild 命令行的方式,也许您可​​以通过这种情况获得路径:stackoverflow.com/questions/12907236/…
    • @Jaffer Sathick,请将该解决方案标记为答案,因为它已解决,我编辑我的答案:)
    • 不适用于 VS2019 IDE(不是命令行)。
    【解决方案2】:

    经过几个小时的战斗,我想我想出了非常简单且通用的解决方案。我发现没有一个解决方案对我有用(“发布”目标仅适用于 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)。 就是这样。

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2022-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      相关资源
      最近更新 更多