确定的MSBuild CoreCompile将运行并调用自定义目标 [英] Determine if MSBuild CoreCompile will run and call custom target

查看:642
本文介绍了确定的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个项目交流#解决方案和詹金斯构建服务器上运行构建脚本驱动的MSBuild。的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可以测试,看看是否编译会发生,可以工作。我也知道如何确定编译运行,因此有条件地做一些后期处理这是可能的,但不理想。

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?

推荐答案

在最终解决办法是的从MSDN论坛条目的和信息=http://social.msdn.microsoft.com/Forums/eu/msbuild/thread/e2b77ab3-b8bb-41d1- 83b3-fe1e46fdc4de>执行目标时(核心)编译将执行

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'.

我基本上采取了赛义德的注射方法来获取我的目标运行'延长-corecompile.proj在所有项目上,而无需编辑每一个凸出的文件,但替换它的内容与一个覆盖'指向了采用相同的输入和输出作为一个自定义的目标CoreCompile目标CoreCompileDependsOn。最终的结果是,只有在运行时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.

感谢所有为他们的意见,这里是骨架我的代码中使用延长-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将运行并调用自定义目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆