sfun28
asked on
MsBuild: target parameters
Hello Experts,
how can I write a target such that it takes an input parameter. For example, lets say I have a target MyTarget that calls MyTask. I want to call MyTarget twice. Once with setting the Property MyTask.MyProperty = true and anohter time with MyTask.MyProperty = false. I don't want to have to write two tasks where I hardcode MyProperty.
is this possible?
how can I write a target such that it takes an input parameter. For example, lets say I have a target MyTarget that calls MyTask. I want to call MyTarget twice. Once with setting the Property MyTask.MyProperty = true and anohter time with MyTask.MyProperty = false. I don't want to have to write two tasks where I hardcode MyProperty.
is this possible?
ASKER
hi Kate,
I think there's a misunderstanding about my question. Let me provide an example of what i'm trying to accomplish.
I'm trying to reuse MyTarget, but provide a parameter value to MyTarget. In the example below, I only need to specify MyTarget once, then I can call it with MyProperty = true and MyProperty = false. Is this possible?
<Target Name="All" DependsOnTargets="$(AllDep endsOn)">
</Target>
<PropertyGroup>
<AllDependsOn>
MyTarget (set MyProperty = false)
MyTarget (set MyProperty = true)
</AllDependsOn>
</PropertyGroup>
<MyTarget>
<MyTask MyProperty = [PARAMETER HERE] >
...
</MyTarget>
I think there's a misunderstanding about my question. Let me provide an example of what i'm trying to accomplish.
I'm trying to reuse MyTarget, but provide a parameter value to MyTarget. In the example below, I only need to specify MyTarget once, then I can call it with MyProperty = true and MyProperty = false. Is this possible?
<Target Name="All" DependsOnTargets="$(AllDep
</Target>
<PropertyGroup>
<AllDependsOn>
MyTarget (set MyProperty = false)
MyTarget (set MyProperty = true)
</AllDependsOn>
</PropertyGroup>
<MyTarget>
<MyTask MyProperty = [PARAMETER HERE] >
...
</MyTarget>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
and there's no easier way to do this? this seems a bit complex just to reuse a <Target>
Well, it doesn't sound that complicated to me anymore. :D
The task is being reused many times over so it payed itself (for us that is).
And you only put:
<MyTarget>
<MyTask MyProperty = "$(MySwitch)" />
</MyTarget>
Which isn't that crazy to follow.
Anyway I'm not aware (at this moment) of any other way, but then again, I'm not exactly a MsBuild guru.
regards,
Kate
The task is being reused many times over so it payed itself (for us that is).
And you only put:
<MyTarget>
<MyTask MyProperty = "$(MySwitch)" />
</MyTarget>
Which isn't that crazy to follow.
Anyway I'm not aware (at this moment) of any other way, but then again, I'm not exactly a MsBuild guru.
regards,
Kate
ASKER
i was hoping not to use environment vars.
anyways, thanks for helping!
anyways, thanks for helping!
You're welcome, I'm sorry but I honestly don't know any other solution to this problem. I'm working at a pretty big company, yet still nobody was able to come with better solution to this problem (local gurus included). I can give you only my confidence that this is the final solution of the huge international company. So you're not alone ;)
regards,
Kate
regards,
Kate
Then you use it in your target like this:
<MyTask MyProperty="true">
</MyTask>
OR (obviously :)
<MyTask MyProperty="false">
</MyTask>
regards,
Kate
Open in new window