6

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

我了解到发布操作的设置由 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在网站复制到输出文件夹后执行该文件?

4

1 回答 1

10

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

<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>
于 2017-05-17T19:52:11.097 回答