如何从 MSBUILD 覆盖 .NET 中引用的 CopyLocal(私有)设

时间:2023-04-01
本文介绍了如何从 MSBUILD 覆盖 .NET 中引用的 CopyLocal(私有)设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为此苦苦挣扎了几天,经过大量搜索后,我找不到我应该走的路.

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模板网!

上一篇:我可以在 Visual Studio 中设置 LARGEADDRESSAWARE 吗? 下一篇:是否可以在没有 Visual Studio 的情况下安装 C# 编译

相关文章

最新文章