使用解决方案信息的msbuild脚本 [英] msbuild script utilizing solution information

查看:81
本文介绍了使用解决方案信息的msbuild脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个csproj文件,它是两个不同的Visual Studio解决方案的一部分.项目文件的行为应略有不同,具体取决于要使用的解决方案.我需要的是可用作条件"的东西-一个名为$(SolutionName)的属性-自动填写. 至少,这是我的想法.我没找到类似的东西.

I have a csproj file, being part of two different Visual Studio solutions. The project file should be able to behave slightly different, depending on the solution it will be used from. What I would need, is something usable as a 'Condition' - a property named for example $(SolutionName) - filled in automagically. At least, this is my idea. I didn't found anything like that.

我还考虑过要导入共同部分的两个小项目文件.我猜这将阻止在Visual Studio内部编辑所有这些属性.它将只在活动的主文件"中写入更改,对吗?

I also considered to have two small project files importing the common parts. This would prevent editing all these properties from inside Visual Studio, I guess. It would write changes only in the active 'master file', correct?

那么,还有其他方法可以使用解决方案信息在项目级别进行区分吗?

So, is there any other way to discriminate at project level using solution information?

推荐答案

原来有一个名为$(SolutionName)的属性.试试这个;首先将环境变量设置为:

Turns out there is a property named exactly $(SolutionName). Try this; first set an environment variable as:

> set MSBuildEmitSolution=1

然后从同一命令行使用MSBuild构建解决方案文件

Then build your solution file using MSBuild from the same command line

> MSBuild My.sln

您将找到解决方案文件的MSBuild项目转换,它将命名为 My.sln.metaproj .

You will find the MSBuild project transformation of your solution file, it will be named My.sln.metaproj.

只需在文本编辑器中将其打开,即可看到其他属性.检查此投影文件中的生成"目标,您可以看到所有这些属性在生成项目时都传递给了MSBuild任务,因此您应该能够根据任何条件来区分条件.

Just open that in a text editor and you can see the other properties. Examine the "Build" target in this projectd file, you can see that all these properties are passed in to the MSBuild task when it builds your projects, so you should be able to discriminate conditions based on any of them.

这篇关于使用解决方案信息的msbuild脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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