MSBuild-设置解决方案的属性 [英] MSBuild - Set Properties For Solution

查看:130
本文介绍了MSBuild-设置解决方案的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在VS2008中使用.NET 3.5.我有一个解决方案,其中包含约20个项目,并且随着应用程序的增长和添加新模块,该数字将随着时间的推移而增长.今天,我需要在每个项目上设置一个属性.我必须编辑每个csproj文件以添加以下内容:

We are using .NET 3.5 with VS2008. I have a solution with ~20 projects in it, and that number will grow over time as the application grows and adds new modules. Today I needed to set a property on every project. I had to edit each csproj file to add the following:

  <Target Name="BeforeBuild">
    <CreateProperty Condition=" '$(SolutionDir)' != '' And '$(SolutionDir)' != '*Undefined*' " 
                    Value="$(SolutionDir)Tools\MSBuild">
      <Output TaskParameter="Value" PropertyName="AlToolPath" />
    </CreateProperty>
  </Target>

这是为了使项目能够找到存储在我的源存储库中的程序集链接器(AL.exe),以便该版本与计算机无关(可以在使用.NET的任何计算机上签出并进行构建,而无需安装.NET) SDK).该解决方案由开发人员使用MSBuild在命令行上构建,安装批处理文件,CCNet等.

This is to enable the projects to find the assembly linker (AL.exe) that is stored in my source repository so that the build is machine agnostic (can check out and build on any machine with .NET without having to install the SDK). The solution is built on the command line using MSBuild by developers, install batch files, CCNet, etc.

无论如何,我一直在寻找一种更好的方法(例如,解决方案级别的属性),但是找不到.我知道可以在MSBuild命令行中设置属性值,但是这对我来说并不理想,因为所有现有和将来的命令行都必须包含它.我还考虑过在第一个构建项目中调用before目标以使用自定义任务来设置环境变量,并在最后一个项目中调用after目标来将其删除,但是这看起来比单独编辑所有项目文件更加繁琐和脆弱

Anyway, I searched for a better way to do this (i.e. something like solution level properties) but could not find one. I know that it is possible to set the property value in the MSBuild command line, but that doesn't scale well for me since all existing and future command lines would have to include it. I also thought about calling a before target in the first built project to use a custom task to set an environment variable, and an after target in the last project to remove it, but that seemed more heavy and brittle than just editing all project files individually.

请让我知道您是否做过这样的事情,或者是否知道可以为每个解决方案设置一次属性的方法,该方法可以被多个项目使用(包括我没有经验的.NET 4/VS2010).请记住,我们使用MSBuild而不是单个项目来构建sln文件.

Please let me know if you have done something like this or know a way to set a property once per solution that can be utilized by multiple projects (including .NET 4/VS2010 which I have no experience with). Remember that we are using MSBuild to build the sln file, not individual projects.

推荐答案

您可以在单个文件中指定此属性以及所有其他常见属性,并通过在项目文件中包含

You can specify this property, and all the other common ones, in a single file, and load it by including in your project files an Import statement. This is what we do in our build environment, which has something like 220 built projects and multiple shared project files (e.g., "branch"). It works well.

这篇关于MSBuild-设置解决方案的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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