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...
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With