在VS2017 Asp.Net Core末尾执行.bat文件?

Ron*_*n C 5 msbuild pubxml asp.net-core-mvc visual-studio-2017

在Visual Studio 2017中,使用文件系统发布方法发布Asp.Net Core网站时,我想.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>
Run Code Online (Sandbox Code Playgroud)

根据.pubxml文件中的注释和其他研究,据我了解,此文件实质上是msbuild文件,最终使用msbuild来执行发布操作。msbuild文件看起来非常灵活,但是有点复杂。我真的很努力与此。

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

Mar*_*ich 6

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

<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>
Run Code Online (Sandbox Code Playgroud)