确定 MSBuild CoreCompile 是否将运行并调用自定义目

Determine if MSBuild CoreCompile will run and call custom target(确定 MSBuild CoreCompile 是否将运行并调用自定义目标)

本文介绍了确定 MSBuild CoreCompile 是否将运行并调用自定义目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎是一件显而易见的事情,但我已经竭尽全力试图在网上找到任何示例或自己做.

This seems like an obvious thing to want to do but I have pulled most of my hair out trying to find any examples on the web or do it myself.

我有一个包含 19 个项目的 c# 解决方案和一个运行构建脚本来驱动 MSBuild 的 Jenkins 构建服务器.MSBuild 当然会根据输入与输出来确定需要编译和不需要编译的内容.

I have a c# solution with 19 projects and a Jenkins build server running a build script to drive MSBuild. MSBuild will of course determine what does and does not need to be compiled based on inputs versus outputs.

我正在尝试创建一个自定义目标,以有条件地更新 MSBuild 将要编译的那些项目的 AssemblyInfo.cs 以增加文件版本.当然,我不想让项目单独编译.

I am trying to create a custom target to conditionally update the AssemblyInfo.cs of those projects MSBuild is going to compile to increment the file versions. Of course I want to leave the projects not being compiled alone.

我知道如何在每次运行的 CoreBuild 之前注入一个目标,所以如果有一些变量,我可以测试看看是否会发生可以工作的编译.我也知道如何确定编译是否运行,因此有条件地进行一些可能但不理想的后处理.

I know how to inject a target prior to the CoreBuild that runs every time so if there is some variable I can test to see if a compile will occur that can work. I also know how to determine if a compile ran and therefore conditionally do some post processing which is possible but not ideal.

如何调整我的构建过程来实现这一点?

How can I tweak my build process to achieve this?

由于这个问题似乎没有直接的答案,有谁知道如何执行与 MSBuild 相同的逻辑来确定哪些项目需要重建?

Since it seems there's no straight answer to the question, does anyone know how to perform the same logic as MSBuild to determine what projects require a rebuild?

推荐答案

最终解决方案是结合 Sayed Ibrahim Hashimi 的博客条目 和来自 MSDN 论坛条目的信息 '当(核心)编译将执行时执行目标'.

In the end the solution was a combination of Sayed Ibrahim Hashimi's blog entry and information from the MSDN Forum entry 'Execute target when (core)compile will execute'.

我基本上采用了 Sayed 的注入方法来让我的目标在所有项目上运行extend-corecompile.proj",而无需编辑每个 proj 文件,但将其内容替换为指向自定义目标的CoreCompileDependsOn"覆盖采用与CoreCompile"目标相同的输入和输出.最终结果是一个仅在CoreCompile"运行且在构建脚本中集中管理时运行的目标.

I basically took Sayed's injection method to get my target to run 'extend-corecompile.proj' on all projects without having to edit each proj file but replaced it's contents with an override for 'CoreCompileDependsOn' that points to a custom target that adopts the same inputs and outputs as the 'CoreCompile' target. The end result is a target that only runs when 'CoreCompile' will run while being centrally managed in the build script.

感谢大家的投入,这是我在extend-corecompile.proj"中使用的框架代码:

Thanks to all for their input and here is the skeleton code I used in 'extend-corecompile.proj':

<!--The following property group adds our custom post-target to the post compile call list -->
<PropertyGroup>
    <TargetsTriggeredByCompilation>
        $(TargetsTriggeredByCompilation);
        CustomPostTarget
    </TargetsTriggeredByCompilation>
</PropertyGroup>

<!--The following property group adds our custom pre-target to CoreCompileDependsOn to ensure it is called before CoreCompile -->
<PropertyGroup>
    <CoreCompileDependsOn>
        $(CoreCompileDependsOn);
        CustomPreTarget
    </CoreCompileDependsOn>
</PropertyGroup>

<!-- The following custom pre-target has the same inputs and outputs as CoreCompile so that it will only run when CoreCompile runs.
    Because we have injected this file and Targets are resolved in sequence we know this Target will fire before CoreCompile.-->
<Target Name="CustomPreTarget" 
    Inputs="$(MSBuildAllProjects);
            @(Compile);                               
            @(_CoreCompileResourceInputs);
            $(ApplicationIcon);
            $(AssemblyOriginatorKeyFile);
            @(ReferencePath);
            @(CompiledLicenseFile);
            @(EmbeddedDocumentation); 
            $(Win32Resource);
            $(Win32Manifest);
            @(CustomAdditionalCompileInputs)"
    Outputs="@(DocFileItem);
             @(IntermediateAssembly);
             @(_DebugSymbolsIntermediatePath);                 
             $(NonExistentFile);
             @(CustomAdditionalCompileOutputs)">
    <!--Do pre-compilation processing here-->
</Target>

<!--This target will be called by CoreCompile-->
<Target Name="CustomPostTarget" >
    <!--Do post-compilation processing here-->
</Target>

不确定如果 CoreCompile 失败会发生什么,它仍然调用我们的目标吗?我想我们会及时发现:)

Not sure what will happen if CoreCompile fails, does it still call our target? I guess in time we'll find out :)

这篇关于确定 MSBuild CoreCompile 是否将运行并调用自定义目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:确定 MSBuild CoreCompile 是否将运行并调用自定义目

基础教程推荐