tags:

views:

19

answers:

1

In mytask.targets, I have something like:

<UsingTask TaskName="DoStuff" AssemblyFile="....etc....."/>
<PropertyGroup>
  <RequiredParamDefault>hello</RequiredParamDefault>
</PropertyGroup>

This task currently has a required parameter (which could be changed from required if necessary).

When the task is used:

<DoStuff RequiredParam="$(RequiredParamDefault)" OtherParam="wobble"/>

Currently, RequiredParam has to be specified everytime. Is there anyway that when UsingTask is defined, the default can be set up so it doesn't have to be specified on every use of DoStuff?

I know the default could be hardcoded in the assembly, but I'd like to be able to define different defaults with different UsingTask statements.

Thanks.

+2  A: 

You can't do this at the UsingTask or Task but instead you can using properties that you pass into the task. For example.

<Target>
    <PropertyGroup>
        <ReqParam Condition=" '$(ReqParam)'=='' ">Param-Default-Value</ReqParam>
    </PropertyGroup>

    <DoStuff RequiredParam="$(ReqParam)" OtherParam="wobble"/>
</Target>

In this case I define the property ReqParam to be Param-Default-Value only if the property doesn't already have a value. This is not exactly what you are looking for, but it may be your best option unless you can change the task itself.

Sayed Ibrahim Hashimi
Hi. Thanks for the suggestion. My intention really is to avoid having to mention RequiredParam in the call to DoStuff. And, I can change the task itself.
Scott Langham