問題描述
這似乎是一件顯而易見的事情,但我已經竭盡全力試圖在網上找到任何示例或自己做.
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 是否將運行并調用自定義目標的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!