1

如何在运行时停止运行 .csproj 文件中<Exec>标签中的命令?我可以停止使用整个部分吗?<Target>dotnet publish --no-build ...<Target>

样本:

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

1 回答 1

2

CLI 参数--no-build将 msbuild 属性设置NoBuild为 true

        public static readonly Option NoBuildOption = new Option<bool>("--no-build", LocalizableStrings.NoBuildOptionDescription)
            .ForwardAs("-property:NoBuild=true");

dotnet 文档也指出了这一点:

这可以通过将--no-build属性传递给 来避免dotnet.exe,这相当于在项目文件中<NoBuild>true</NoBuild>设置,以及<IncludeBuildOutput>false</IncludeBuildOutput>在项目文件中设置。

您应该能够在Condition支票中测试该属性:

<Target ... Condition="'$(Configuration.ToUpper())' == 'RELEASE' and '$(NoBuild)' != 'true' ">
...
于 2021-01-08T16:42:41.290 回答