msbuild script utilizing solution information

时光总嘲笑我的痴心妄想 提交于 2019-12-19 03:54:08

问题


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.

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?


回答1:


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

> set MSBuildEmitSolution=1

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

> MSBuild My.sln

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

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.



来源:https://stackoverflow.com/questions/5556168/msbuild-script-utilizing-solution-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!