I'm trying to define a PostBuildEvent that will publish the project and then build the docker image:
<Target Name="DockerBuild" AfterTargets="PostBuildEvent">
<Message Text="========== PostBuildEvent - Building Docker Image ==========" Importance="high" />
<Exec Command="dotnet publish $(ProjectDir)\MyProject.csproj -c Release -o ./app/publish /p:UseAppHost=true /p:PostBuildEvent=" />
<Exec Command="docker build -t myimagename ." />
<Exec Command="docker image prune --force" />
</Target>
However, this seems to trigger an infinite loop of build events.
I'm aware that dotnet publish will also do a build, but I thought that the /p:PostBuildEvent= parameter would negate that.
How can I configure the publish command to skip the PostBuildEvent?
/p:PostBuildEvent=sets the$(PostBuildEvent)property to'', which is very different from resetting the targetPostBuildEvent*. See: MSBuild CLI Reference.I suggest adding a Condition attribute to the Target and setting that instead.
*: The target
PostBuildEventcan be reset using<Target Name="PostBuildEvent" />.