AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

AfterPublish -> Publish

Open CeciAc opened this issue 6 years ago • 6 comments

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.

CeciAc avatar Jun 01 '20 21:06 CeciAc

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 avatar Jun 01 '20 22:06 Rick-Anderson

@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.

BerndK avatar Jun 05 '20 01:06 BerndK

@sayedihashimi should I make this change? Have these targets changed?

Rick-Anderson avatar Jun 05 '20 01:06 Rick-Anderson

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.

sayedihashimi avatar Jun 05 '20 02:06 sayedihashimi

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

vijayrkn avatar Jun 05 '20 03:06 vijayrkn

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.

BerndK avatar Jun 06 '20 16:06 BerndK