以下是我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
,则会正确部署。这只是我项目的简化示例。
我该如何解决这个问题?
答案 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。它使用它来兼容。