Open
Description
So I was looking around to see if I could redefine some defaults to always be true iff we run a Publish action.
I could only seem to get there by chaining msbuild gotchas, essentially having a project like:
<Project>
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
<Target Name="OldPublish" DependsOnTargets="_PublishBuildAlternative;_PublishNoBuildAlternative">
<!-- Ensure there is minimal verbosity output pointing to the publish directory and not just the
build step's minimal output. Otherwise there is no indication at minimal verbosity of where
the published assets were copied. -->
<Message Importance="High" Text="$(MSBuildProjectName) -> $([System.IO.Path]::GetFullPath('$(PublishDir)'))" />
</Target>
<Target Name="NewDefaults">
<PropertyGroup>
... Override defaults here
</PropertyGroup>
</Target>
<Target Name="Publish"
DependsOnTargets="NewDefaults"
Condition="$(IsPublishable) == 'true'">
// We actually need NewDefaults as a separate target to set the props
// due to a long standing CallTarget bug https://github.com/Microsoft/msbuild/issues/1006
<CallTarget Targets="NewPublish" />
</Target>
</Project>
The pain here is mainly that you cannot get any custom evalution in before /t: Publish
— without doing crazy stuff — there's only the indifferent InitialTargets.
Problem there obviously is if you really need a Target to only run before Publish, not always.
Is there anything we can do better here?
It looks I'm not the first either #1039, although there it seems BeforePublish was still a thing.