在 VS2017 结束时执行 .bat 文件 Asp.Net 核心发布操作?

Execute .bat file at end of VS2017 Asp.Net Core publish action?

在 Visual Studio 2017 年使用文件系统发布方法发布 Asp.Net 核心网站时,我想在发布操作将文件复制到之后触发 .bat 文件的执行输出目录。

我了解到发布操作的设置由 Visual Studio 存储在项目的 Properties/PublishProviles 目录中的 .pubxml 文件中。所以在可能的情况下,文件是 FolderProfile.pubxml 并且它当前看起来像这样:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
    This file is used by the publish/package process of your Web project. You can customize the behavior of this process
    by editing this MSBuild file. In order to learn more about this please visit https://go.microsoft.com/fwlink/?LinkID=208121. 
    -->
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <PublishProvider>FileSystem</PublishProvider>
        <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <LaunchSiteAfterPublish>False</LaunchSiteAfterPublish>
        <ExcludeApp_Data>False</ExcludeApp_Data>
        <PublishFramework>net461</PublishFramework>
        <ProjectGuid>f58b5ca0-8221-4c97-aa6d-7fba93a3abeb</ProjectGuid>
        <publishUrl>C:\inetpub\wwwGiftOasisResponsivePublished</publishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
      </PropertyGroup>
    </Project>

根据 .pubxml 文件中的注释和其他研究,我认为该文件本质上是一个 msbuild 文件,最终 msbuild 用于执行发布操作。 msbuild 文件看起来非常灵活,但有点复杂。我真的很纠结这个。

如果我的项目根目录中有一个名为 finishPub.bat 的批处理文件,我该如何修改上面的 .pubxml 文件以在 finishPub.bat 文件之后执行网站已复制到输出文件夹?

您可以使用自定义目标修改您的发布配置文件:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    ...
  </PropertyGroup>
  <Target Name="ExecuteBatAfterPublish" AfterTargets="AfterPublish">
    <Exec Command="example.bat" WorkingDirectory="$(publishUrl)" />
  </Target>
</Project>