开发者

How can task parameters be defaulted in MSBuild

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 default开发者_如何学编程s with different UsingTask statements.

Thanks.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜