部署控制台应用程序时用于复制其他文件的 MS Build 配置

MS Build configuration to copy additional files when deploying console app

我有一个 .net 控制台应用程序,我将其部署到 Team City CI 环境中的服务器。构建过程使用 MSBuild 配置,应用程序使用 MSDeploy 部署。

应用程序本身部署正常,但我现在想将一组模板(文件)部署到同一目标目录。我有一个 WebApi 应用程序,它使用 MSBuild WebApplication.targets 成功部署了相同的组件和模板,并根据 this post 锁定到 CopyAllFilesToSingleFolderForMsdeploy 目标。但是,我无法让这种方法适用于控制台应用程序。

我也试过在 AfterBuild 目标中直接复制文件。

.csproj 项目文件的相关部分如下所示:

<Target Name="AfterBuild" Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PropertyGroup>
        <TemplatePath>$([System.IO.Path]::Combine($([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory))), `MyApp.MyComponent\Messages\Views`))</TemplatePath>
    </PropertyGroup>
    <ItemGroup>
        <Templates Include="$(TemplatePath)\**\*.cshtml" />
    </ItemGroup>
    <Message Text="Template Path = $(TemplatePath)" Importance="high" />
    <Copy SourceFiles="@(Templates)" DestinationFolder="$(OutputPath)\Templates\%(Templates.RecursiveDir)" />
</Target>

我做错了吗?想要做的事情似乎很简单,但我找不到让它工作的方法。

这最终奏效了:

<PropertyGroup>
    <GetCopyToOutputDirectoryItemsDependsOn>
        $(GetCopyToOutputDirectoryItemsDependsOn);
        CustomCollectFiles
    </GetCopyToOutputDirectoryItemsDependsOn>       
</PropertyGroup>
<Target Name="CustomCollectFiles">
    <PropertyGroup>
        <TemplatePath>$([System.IO.Path]::Combine($([System.IO.Path]::GetDirectoryName($(MSBuildProjectDirectory))), `MyApp.MyComponent\Messages\Views`))</TemplatePath>
    </PropertyGroup>
    <Message Text="Template Path = $(TemplatePath)" Importance="high" />
    <ItemGroup>
        <CustomFilesToInclude Include="$(TemplatePath)\**\*.cshtml" />
    </ItemGroup>
    <Message Text="CustomCollectFiles = @(CustomFilesToInclude)" Importance="high" />
    <Copy SourceFiles="@(CustomFilesToInclude)" DestinationFolder="$(OutputPath)\Templates\%(CustomFilesToInclude.RecursiveDir)" />
</Target>