mark
mark

Reputation: 62712

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...

Upvotes: 4

Views: 1411

Answers (1)

mark
mark

Reputation: 62712

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.

Upvotes: 4

Related Questions