dotnet发布不包括在构建后事件期间生成的文件

时间:2017-09-01 10:59:02

标签: c# asp.net .net asp.net-web-api

以下是我A.csproj的一部分:

 <ItemGroup>
    <Content Include="..\..\Payloads\**\*.*">
      <Link>Payloads\%(RecursiveDir)%(FileName)%(Extension)</Link>
      <CopyToOutputDirectory>None</CopyToOutputDirectory>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

Payloads目录在项目B中创建,该项目从项目A

引用
B.csproj

 <PropertyGroup>
    <PostBuildEvent>
      xcopy /I /S /R /Y /d $(TargetDir)*.* $(SolutionDir)Payloads\Content
    </PostBuildEvent>
  </PropertyGroup>
当我运行Payloads

时,publish目录中不存在

dotnet publish目录

信息

dotnet SDK version 2.0, ASP.NET Core 2.0 on .NET 461 framework

似乎发布内容是在构建之前计算的。当我运行dotnet发布时,如果存在Payloads,则会正确部署。这只是我项目的简化示例。  我该如何解决这个问题?

1 个答案:

答案 0 :(得分:2)

我替换了

 <ItemGroup>
    <Content Include="..\..\Payloads\**\*.*">
      <Link>Payloads\%(RecursiveDir)%(FileName)%(Extension)</Link>
      <CopyToOutputDirectory>None</CopyToOutputDirectory>
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </Content>
  </ItemGroup>

使用

 <Target Name="AddPayloadsFolder" AfterTargets="AfterPublish">
        <PropertyGroup>
          <PayloadsDirectory>$(SolutionDir)Payloads</PayloadsDirectory>
        </PropertyGroup>
        <Exec Command="xcopy.exe /I /S /R /Y /d $(PayloadsDirectory) $(PublishDir)Payloads" Condition="!Exists('$(PublishDir)Payloads')" />
        <Exec Command="xcopy.exe /I /S /R /Y /d $(PayloadsDirectory) $(PublishUrl)Payloads" Condition="!Exists('$(PublishUrl)Payloads')" />
      </Target>

PublishUrl的版本适用于Visual Studio。它使用它来兼容。