仅在 .NET Core 3.1 项目中重建目标
Target rebuild only in a .NET Core 3.1 project
在编译 .NET Core 3.1 控制台应用程序时,我想 仅 在重建(而非构建)时执行命令。我可以成功使用“PreBuild”事件,但它会在 both Build & Rebuild 上执行。这是我要实现的目标的示例:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<Target Name="BeforeRebuild" BeforeTargets="Rebuild">
<Exec Command="foo" />
</Target>
</Project>
正如所写,命令永远不会执行。我认为问题在于“重建”不是有效目标。
试试这个:
<Target Name="This is a custom rebuild event" BeforeTargets="BeforeRebuild">
<Exec Command="echo You did a rebuild" />
</Target>
更多信息here。
在编译 .NET Core 3.1 控制台应用程序时,我想 仅 在重建(而非构建)时执行命令。我可以成功使用“PreBuild”事件,但它会在 both Build & Rebuild 上执行。这是我要实现的目标的示例:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<Target Name="BeforeRebuild" BeforeTargets="Rebuild">
<Exec Command="foo" />
</Target>
</Project>
正如所写,命令永远不会执行。我认为问题在于“重建”不是有效目标。
试试这个:
<Target Name="This is a custom rebuild event" BeforeTargets="BeforeRebuild">
<Exec Command="echo You did a rebuild" />
</Target>
更多信息here。