Here is part of my A.csproj
:
<ItemGroup>
<Content Include="..\..\Payloads\**\*.*">
<Link>Payloads\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>None</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
Payloads
directory is created in a project B
which is referenced from project A
B.csproj
<PropertyGroup>
<PostBuildEvent>
xcopy /I /S /R /Y /d $(TargetDir)*.* $(SolutionDir)Payloads\Content
</PostBuildEvent>
</PropertyGroup>
Payloads
directory doesn't exist in publish
directory when I run dotnet publish
Info
dotnet SDK version 2.0, ASP.NET Core 2.0 on .NET 461 framework
It seems like publish content is calculated before the build. When I run dotnet publish if Payloads
exists it is deployed correctly. This is just simplified example of my projects. How can I fix this?
I replaced
<ItemGroup>
<Content Include="..\..\Payloads\**\*.*">
<Link>Payloads\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>None</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
With
<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>
The version with PublishUrl is for Visual Studio. It uses it for compatibility.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.