sdk
sdk copied to clipboard
"AfterPublish" doesn't not invoked
Describe the bug

ASP.Net Core project

To Reproduce
- download the Avalonia Gallery
- create a task that depends on "AfterPublish" task
dotnet publish- "AfterPublish" and custom task doesn't not invoked
- 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
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.
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.
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.
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
AfterPublishevent. 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>
<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.