假设我有两个项目文件"Parent.proj"和"Child.proj".如果我在Parent.proj中声明一个属性,MyProp我可以使用以下代码将其传递给Child.proj:
<MSBuild Projects="Child.proj" Targets="dostuff" Properties="MyProp=MyValue" />
Run Code Online (Sandbox Code Playgroud)
这很好,但我想知道MyProp在Child.proj中是否有一种引用方式,而Child.proj没有调用Child.proj.
我知道我可以在Child.proj中声明相同的属性,当Parent.proj调用Child.proj时,这将被覆盖,但我想避免重复属性值.
如果在外部项目文件中定义属性,则每个项目都可以导入属性设置.
这是一个非常简单的属性文件,名为orders.properties,我目前正在处理它.
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- always include the root properties -->
<Import Project="$(root)\root.properties.proj"/>
<PropertyGroup>
<!-- Version numbers/names for this branch -->
<orders_ver_major>99</orders_ver_major>
<orders_ver_minor>0</orders_ver_minor>
<orders_ver_release>0</orders_ver_release>
<orders_ver>$(orders_ver_major).$(orders_ver_minor).$(orders_ver_release)</orders_ver>
<orders_ver_db>$(orders_ver_major)_$(orders_ver_minor)_$(orders_ver_release)</orders_ver_db>
<!-- setup folders specific to the orders project -->
<orders_database>$(orders_root)\btq.orders.database</orders_database>
<!--
Setup order database default properties, can be overriden if passed in when called from
the command line or from other build scripts.
-->
<orders_force_create Condition="'$(orders_force_create)' == ''">false</orders_force_create>
<orders_db_server Condition="'$(orders_db_server)' == ''" >.\sqlexpress</orders_db_server>
<orders_db_username Condition="'$(orders_db_username)' == ''" >yyyyyyyy</orders_db_username>
<orders_db_password Condition="'$(orders_db_password)' == ''" >xxxxxx</orders_db_password>
<orders_db_name Condition="'$(orders_db_name)' == ''" >$(COMPUTERNAME)_btq_orders_v$(orders_ver_db)</orders_db_name>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
在我的主构建项目中,我导入orders.build.proj文件中的订单属性以及需要它的任何子项目.
这是主构建文件的初始部分.
<Project DefaultTargets="build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Always setup the path to the root and also the orders root folder.
We then include the orders properties, which includes the root properties
For this project the orders folder is in the same folder as this build file
so can just reference the ms build project directory property as the orders_root.
-->
<PropertyGroup>
<root>$(MSBuildProjectDirectory)\..\..</root>
<orders_root>$(MSBuildProjectDirectory)</orders_root>
</PropertyGroup>
<!--
Once we have the roots configured we can now include all the standard properties,
this also includes the root.properties also.
-->
<Import Project="$(orders_root)\orders.properties.proj"/>
Run Code Online (Sandbox Code Playgroud)
希望这能回答你的问题.
亲切的问候诺埃尔
| 归档时间: |
|
| 查看次数: |
3903 次 |
| 最近记录: |