如果您在外部項目文件中定義屬性,則每個項目都可以導入屬性設置。
下面是一個非常簡單的屬性文件,我稱之爲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>
在我的主要生成項目中,我在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"/>
希望這回答你的問題。
親切的問候 諾埃爾
+1輝煌!將屬性放在單獨的文件中以防止雙向依賴性是一個好主意。非常感謝! – 2009-06-05 10:47:38
有沒有辦法調用任務以及哪些可以設置這些全局屬性。創建名爲buildDate的屬性,然後用
您可以隨時通過屬性函數在構建目標中的任何屬性中添加時間戳。例如,在Target的PropertyGroup部分設置 $(DateTime.Now) MyTimestamp>。請參閱http://msdn.microsoft.com/en-us/library/dd633440.aspx。 –
d3r3kk
2014-10-31 21:52:46