How can I stop commands in <Exec>
tags within a <Target>
in my .csproj file from running when I run dotnet publish --no-build ...
? Can I stop the entire <Target>
section from being used?
Sample:
<Target Name="BuildSpa" BeforeTargets="Build" AfterTargets="ComputeFilesToPublish" Condition="'$(Configuration.ToUpper())' == 'RELEASE'">
<Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
<Exec WorkingDirectory="$(SpaRoot)" Command="npm run build" />
</Target>
The CLI argument --no-build
sets the msbuild property NoBuild
to true:
public static readonly Option NoBuildOption = new Option<bool>("--no-build", LocalizableStrings.NoBuildOptionDescription)
.ForwardAs("-property:NoBuild=true");
The dotnet docs also call this out:
This can be avoided by passing
--no-build
property todotnet.exe
, which is the equivalent of setting<NoBuild>true</NoBuild>
in your project file, along with setting<IncludeBuildOutput>false</IncludeBuildOutput>
in the project file.
You should be able to test for that property in your Condition
check:
<Target ... Condition="'$(Configuration.ToUpper())' == 'RELEASE' and '$(NoBuild)' != 'true' ">
...