Repository navigation
Property Scope
nathanscottdaniels edited this page Oct 17, 2016
·
1 revision
In the original NAnt, properties created in one target or project were visible to all other targets and projects. This is obviously unacceptable for multithreaded targets and so the concept of property scope was added.
<property name="blah" value="x" scope="target"/>
The default scope for all properties is thread.
A new attribute, scope was added to the <property/> task that allows you to specify the scope of the property. The available scopes are:
-
global: This is the scope that all properties had in the original NAnt. With theglobalscope, the property is visible to and modifiable by all targets, tasks, and threads in the build. -
thread: With this scope. a property is visible to all targets and tasks in the current thread. Other threads cannot interfere. When a new<parallel>is created, all thread-scoped properties are copied to the new threads. Therefore, the new threads will have copies of the thread-scoped properties of the parent thread and they can modify their values, but these modifications will only be visible within the child thread leaving the value in the parent thread unchanged. This is sort of like how local variables are handled when afork()function call is made in Unix. -
target: With this scope, a property is only visible to the target and thread that created it. This is equivalent to a local variable in C-type languages. This scope cannot be used for properties defined at the project level.