AfterPublish -> Publish
Moved from: https://github.com/dotnet/AspNetCore.Docs.de-de/issues/67
@BerndK commented 14 hours ago It seems to be not working to use AfterPublish and BeforePublish, use just 'Publish' then it works like: AfterTargets="Publish"
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 684d1f55-3d8b-9ba6-ee65-e8f84c2b4244
- Version Independent ID: 2db330b4-e830-715f-0a15-e406f85e1d3b
- Content: Visual Studio publish profiles (.pubxml) for ASP.NET Core app deployment
- Content Source: aspnetcore/host-and-deploy/visual-studio-publish-profiles.md
- Product: aspnet-core
- Technology: aspnetcore-hostdeploy
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
The following folder publish profile was created with Visual Studio and publishes to a network share:
<?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.
-->
<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>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<PublishFramework>netcoreapp1.1</PublishFramework>
<ProjectGuid>c30c453c-312e-40c4-aec9-394a145dee0b</ProjectGuid>
<publishUrl>\\r8\Release\AdminWeb</publishUrl>
<DeleteExistingFiles>False</DeleteExistingFiles>
</PropertyGroup>
</Project>
@Rick-Anderson Im not talking about the profile.
I wanted to define a task that copies the files to a server (via SCP).
This task should fire after the publish process.
This is defined here: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-3.1#run-a-target-before-or-after-publishing
But this does not work!
Wrong:
<Target Name="CustomActionsBeforePublish" BeforeTargets="BeforePublish">
Correct:
<Target Name="CustomActionsBeforePublish" BeforeTargets="Publish">
Same for AfterTargets.
Hope this more clear now.
@sayedihashimi should I make this change? Have these targets changed?
I'm not sure but @vijayrkn should know.
I believe that the MSBuild targets across Visual Studio have moved away from the "BeforeTargetName" and "AfterTargetName" pattern, so it sounds like it's correct that BeforePublish and AfterPublish no longer are defined in our .targets file.
The current documentation is correct. WebSdk has a "BeforePublish" & "AfterPublish" target that gets executed before and after the core publish operation.
The way to look at it is that the target "Publish" just consolidates all the files to be published but core publish does more than that like running transforms, updating app configs etc. So if something needs to run before that, then it should be based on "BeforePublish" & "AfterPublish"
https://github.com/dotnet/websdk/blob/f012288885a64c36c03aed371f5fba3ff3dc6da2/src/Publish/Targets/Microsoft.NET.Sdk.Publish.targets#L36-L37
Just to mention, that I did not use the websdk, but a .net core 3.1 project that has to be published. Initially I tried the "AfterPublish" (as described in doc) which has not been triggered in my case. But when I switched to "Publish", it worked as expected. Perhaps this is not perfectly consistent on all use cases (different project types might have defined additional targets, which is perfectly fine), perhaps it's worth to mention, that "Publish" might be a good guess for others.