How to auto publish a project just after building?

Tony Enrique Orozco Suarez 0 Reputation points
2024-08-08T19:08:37.28+00:00

When building or rebuilding a solution, I want to automatically publish all the publishable project within my solution.

Developer technologies | .NET | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tony Enrique Orozco Suarez 0 Reputation points
    2024-08-08T19:16:07.79+00:00
    0 comments No comments

  2. Anonymous
    2024-08-09T09:44:40.4+00:00

    Hi @Tony Enrique Orozco Suarez , Welcome to Microsoft Q&A,

    Since Q&A users cannot mark their own answers, I will reorganize and post your answer.


    You can't trigger the web publish via as that's automatically disabled when building from Visual Studio.DeployOnBuild

    You can, however, trigger the process as part of the same MSBuild invocation via some MSBuild trickery:

    <!-- In Directory.Build.props or the csproj (before the web targets import) -->
    <PropertyGroup>
      <PublishProfile>Local</PublishProfile>
    </PropertyGroup>
    

    And also:

    <!-- After the above, or in ProjectName.wpp.targets -->
    <PropertyGroup>
      <AutoPublish Condition="'$(AutoPublish)' == '' and '$(Configuration)' == 'Debug' and '$(BuildingInsideVisualStudio)' == 'true' and '$(PublishProfile)' != ''">true</AutoPublish>
    
      <AutoPublishDependsOn Condition="'$(AutoPublish)' == 'true'">
        $(AutoPublishDependsOn);
        WebPublish
      </AutoPublishDependsOn>
    </PropertyGroup>
    
    <Target Name="AutoPublish" AfterTargets="Build" DependsOnTargets="$(AutoPublishDependsOn)">
    </Target>
    

    If you're finding that your publish project isn't being built when you make content changes, add the following:

    <!-- csproj ONLY, won't work elsewhere -->
    <PropertyGroup>
      <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
    </PropertyGroup>
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.