問題描述
我已經為此苦苦掙扎了幾天,經過大量搜索后,我找不到我應該走的路.
I have been wrestling with this for a few days and after tons of searching I can't find the path I should be on.
我想要做的是設置一個 MSBUILD 項目,它將構建我們的整個 .NET 應用程序(8 個解決方案的常量,并且可能有 250 個項目在它們之間拆分),其中一些設置從單個項目文件中覆蓋以進行自己的調試版本.
What I want to do is set up an MSBUILD project that will build our entire .NET application (constst of 8 solutions, and maybe 250 projects split up between them) with a number of settings overridden from the individual project files to make a debug build for myself.
具體來說,我想構建我們的發布配置,關閉優化并生成完整的調試信息/pdb.另外,為了減少我們目前超長的構建時間,我希望每個項目的每個引用都復制本地"(或實際項目文件 xml 中的私有)為 false.
Specifically I want to build our release configuration with optimizations off and full debug info / pdbs generated. Also, in order to reduce our currently ultra-long build time I want "copy local" (or private in the actual proj file xml) false for every reference of every project.
第一件事很簡單,我可以很容易地覆蓋項目級別的屬性(您甚至可以使用/p 從 MSBuild 命令行執行此操作),但我不知道如何覆蓋一個參考.我已經嘗試了一些我在 StackOverflow 和網絡上看到的東西,但還沒有一個解決方案.
The first things were fairly easy, I can override a project level property fairly easily (you can even do this from the MSBuild command line using /p), but what I can't figure out is how to override a property on a reference. I have tried several things I saw here on StackOverflow and around the web, but nothing is a solution yet.
我可以通過更改 Microsoft.Common.targets 來做我想做的事,注釋掉 _CopyFilesMarkedCopyLocal 目標中的代碼會完全跳過這些文件的復制.但我不想改變我的全局配置并在所有情況下都這樣做.我創建了自己的備用目標文件——如果我改變一個單獨的項目文件以指向它,它就可以工作——但我不知道如何指定它在頂層使用(我的 .proj 文件只是構建所有 8 個解決方案).如果我能以某種方式僅覆蓋頂層的 _CopyFilesMarkedCopyLocal 目標,那就太好了,這樣如果 MS 更改了默認目標文件,我的構建就不會搞砸,但我也不知道如何使它工作.
I can do what I want by altering Microsoft.Common.targets, commenting out the code in the _CopyFilesMarkedCopyLocal target completely skips the copying of these files. But I don't want to alter my global configuration and do this in all circumstances. I created my own alternate targets file -- which works if I alter an individual project file to point to it -- but I can't figure out how to specify this to be used at the top level (my .proj file that just builds all 8 solutions). It would be great if I could somehow override just the _CopyFilesMarkedCopyLocal target at the top level so that if MS changes the default targets file my build isn't screwed up, but I can't figure out how to make this work either.
如果有一種方法可以覆蓋參考級別屬性,就像您可以項目級別屬性一樣,而不必重寫/覆蓋構建目標的東西,那么最好的可能就是 - 但我沒有發現任何信息表明這是可能的.
The best possible thing would be if there was a way to just override reference level properties like you can project level properties, without having to rewrite/override the build targets stuff -- but I have found no information indicating this is possible.
提前感謝您對此提供的任何幫助.
Thanks in advance for any help on this.
附言我實際上不可能瀏覽所有項目文件并更改它們;我需要一個解決方案,讓現有代碼保持原樣.
P.S. It is not possible for me to actually just go through all the projects files and change them; I need a solution that leaves the existing code in place as is.
推薦答案
試試這個:
將 CustomAfterMicrosoftCommonTargets 設置為 C:foofilter.targets (或任何您命名的文件) 并將 filter.targets 設置為:
Set the CustomAfterMicrosoftCommonTargets to C:foofilter.targets (or whatever you name the file) and have filter.targets to be:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemDefinitionGroup>
<Reference>
<Private>False</Private>
</Reference>
</ItemDefinitionGroup>
</Project>
這篇關于如何從 MSBUILD 覆蓋 .NET 中引用的 CopyLocal(私有)設置的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!