gisWeeper
gisWeeper

Reputation: 481

Update property in a script

In my NAnt script I have a property:

<property name="changed.assemblyinfo" value="false" unless="${property::exists('changed.assemblyinfo')}" />

The property can be set from the command line using the -D switch like below, which works fine:

-D:changed.assemblyinfo=true

However, I also want to be able to update the property from within the script itself depending on some logic in the script i.e:

<property name="changed.assemblyinfo" value="true" />

However, every time I do this I get the error:

Read-only property "changed.assemblyinfo" cannot be overwritten

How do I set a property from within the script?

Upvotes: 1

Views: 606

Answers (1)

James Thorpe
James Thorpe

Reputation: 32212

When you pass a property in on the command line, it is treated as a readonly property. From the docs:

iii. Define a read-only property. This is just like passing in the param on the command line.

<property name="do_not_touch_ME" value="hammer" readonly="true" />

That means that you're unable to update it. In your case, if you both need to be able to supply it from the command line and update it depending on logic means that you'll need to supply a default value on the command line that uses a different name, eg:

<property name="changed.assemblyinfo.default" value="false" unless="${property::exists('changed.assemblyinfo.default')}" />
<property name="changed.assemblyinfo" value="${changed.assemblyinfo.default}" />

So now changed.assemblyinfo will contain either the default value of changed.assemblyinfo.default or the value passed in on the command line, while you're free to overwrite it as normal:

<property name="changed.assemblyinfo" value="true" />

Upvotes: 1

Related Questions