Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish the particular .Net Core project automatically whenever it is built by Visual Studio?

I know it is easy on the command line - just run dotnet publish instead of dotnet build, but I am building inside Visual Studio and I want a certain .Net Core project to essentially execute the dotnet publish logic whenever VS builds it.

I am expecting for some kind of a build property. Tried to google it - did not find...

like image 523
mark Avatar asked Oct 31 '25 06:10

mark


1 Answers

I solved it by adding the following lines to the project file:

  <Target Name="SetNoBuild">
    <PropertyGroup>
      <NoBuild>true</NoBuild>
    </PropertyGroup>
  </Target>
  <Target Name="PublishAfterBuild" AfterTargets="AfterBuild" DependsOnTargets="SetNoBuild;Publish" />
  <Target Name="CleanAfterBuild" AfterTargets="AfterClean">
    <RemoveDir Directories="$(PublishDir)" Condition="'$(PublishDir)' != ''"/>
  </Target>

I wonder if there is a simpler approach.

like image 102
mark Avatar answered Nov 01 '25 19:11

mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!