sdk icon indicating copy to clipboard operation
sdk copied to clipboard

"AfterPublish" doesn't not invoked

Open liesauer opened this issue 3 years ago • 1 comments

Describe the bug

image

ASP.Net Core project

image

To Reproduce

  1. download the Avalonia Gallery
  2. create a task that depends on "AfterPublish" task
  3. dotnet publish
  4. "AfterPublish" and custom task doesn't not invoked
  5. if it is a ASP.Net Core project, "AfterPublish" does be invoked.

Exceptions (if any)

both of the two tasks should be invoked

Further technical details

sdk: 6.0.300

liesauer avatar Jul 20 '22 03:07 liesauer

This appears to be because BeforePublish and AfterPublish are only defined for Web SDK projects, not the .NET SDK itself. They are defined here.

We probably should pull this down to the base Microsoft.NET.Publish.targets as well, but that has the potential to be very disruptive. We'll need to bring down the targets themselves, as well as the Property-based extension points. Would likely need @dsplaisted to weigh in on the complexity.

I do think this is a thing we should do, however - publishing isn't something that only Web projects can/should do.

baronfel avatar Aug 04 '22 17:08 baronfel

In the current version (SDK 6.0.401) the only way to get a single file app on the desktop is through publish. If you then want access to that final EXE in an automation, you need an AfterPublish event. I was unable to get this working, I found this issue. Seems to be the same. Being able to publish to a single file is a huge reason why I'm upgrading my desktop projects from Framework. As we go through this process of migrating away from Framework we are all going to need this feature on the Desktop.

A9G-Data-Droid avatar Oct 06 '22 15:10 A9G-Data-Droid

This one slipped through the cracks - I've added it to our triage bucket for discussion. As I stated above, I definitely believe that we need to do this work to enable consistent publish behavior for all project types, not just web projects. We'll also need to consult with @vijayrkn and his team to make sure the VS/Web publish behavior isn't impacted.

baronfel avatar Oct 06 '22 15:10 baronfel

In the current version (SDK 6.0.401) the only way to get a single file app on the desktop is through publish. If you then want access to that final EXE in an automation, you need an AfterPublish event. I was unable to get this working, I found this issue. Seems to be the same. Being able to publish to a single file is a huge reason why I'm upgrading my desktop projects from Framework. As we go through this process of migrating away from Framework we are all going to need this feature on the Desktop.

the last stage of non-web project is Publish, so for now, the following workaround works for me.

<PropertyGroup>
    <_TaskDependsOn Condition="'$(_IsAspNetCoreProject)' == 'true'">AfterPublish</_TaskDependsOn>
    <_TaskDependsOn Condition="'$(_IsAspNetCoreProject)' != 'true'">Publish</_TaskDependsOn>
</PropertyGroup>

<Target Name="CustomTask" AfterTargets="$(_TaskDependsOn)">
    <Message Text="Hello" Importance="High" />
</Target>

liesauer avatar Oct 07 '22 01:10 liesauer

<PropertyGroup>
    <_TaskDependsOn Condition="'$(_IsAspNetCoreProject)' == 'true'">AfterPublish</_TaskDependsOn>
    <_TaskDependsOn Condition="'$(_IsAspNetCoreProject)' != 'true'">Publish</_TaskDependsOn>
</PropertyGroup>

<Target Name="CustomTask" AfterTargets="$(_TaskDependsOn)">
    <Message Text="Hello" Importance="High" />
</Target>

Thank you so much! I tried so many permutations of Publish/AfterPublish. I wasn't able to get anything to fire before. Using this snippet I was able to get my published artifact in a final event! Maybe there needs to be better documentation about how this works in the current LTS version of .NET6 for desktop.

A9G-Data-Droid avatar Oct 10 '22 15:10 A9G-Data-Droid