MSBuild忽略BuildEvent
Solution的Properties界面
这个Build任务在csproj文件中实际上是一个标签 是一个Exec任务
###这里的Target表示Build之后执行的任务 Build之前用PreBuild
这里的任务Command (echo 11 >> a.txt) 代表将"11"写入到名为a.txt的文件中
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo 11 >> a.txt" Condition="'$(RunExternalCommands)'=='true'"/>
</Target>
想要忽略他可以在标签中添加Condition,添加这个之后Rider2022.3在properties窗口中不会显示这个任务,需要看的可以先去掉Condition
RunExternalCommands条件加在PropertyGroup标签内
这里默认给他true 所以默认这个任务是执行的
<PropertyGroup>
<RunExternalCommands>true</RunExternalCommands>
</PropertyGroup>
这句调用是代表用msbuild工具build hotfixPath路径的项目 发布release包 这里要说的是传参RunExternalCommands=false,他会改变PropertyGroup中RunExternalCommands的值
import subprocess
subprocess.call(["dotnet", "msbuild",'-p:configuration="release"', "/p:RunExternalCommands=false", hotfixPath])
最终结果不言而喻,他不会调用到Exec任务
实现这个的目的是为了区别在Rider中打包和用python工具打包,算是一个小知识点,就此记录一下
还有如果想要忽略PostBuildEvent、PreBuildEvent可以直接传参把他置空
dotnet msbuild /t:build /p:configuration=Release /p:PostBuildEvent="" /p:PreBuildEvent=""
结束语:前辈给的工具很强大,所以我们在巨人的肩膀上很幸福