3

I want to make an import dependent on which target I call MSBuild with from the commandline but I'm having a hard time figuring out how to programatically access the target name(s) the .proj file was called with

i.e. <Import Project="some.targets" Condition="$(TargetName) == myTarget"/>

In general is there a way to dump all defined environment variables that exist at proj file runtime?

2
  • duplicate: stackoverflow.com/questions/1140069/msbuild-conditional-imports Commented Jul 28, 2009 at 14:42
  • 2
    I don't think this is a duplicate, that question does not answer the question how to make an import dependent on a MSBuild command line specified target. I already know you can condition imports etc... Commented Jul 28, 2009 at 15:08

1 Answer 1

3

Unfortunately I don't think that you can access the names of the targets specified on the command line from within the build script itself. What are you trying to do, maybe there is another approach you can take.

Sayed Ibrahim Hashimi

My Book: Inside the Microsoft Build Engine : Using MSBuild and Team Foundation Build

Sign up to request clarification or add additional context in comments.

3 Comments

I just want do an import only if a specific target is being called etc... it doesn't appear you can do an import from within a target body either from what I can tell.
You can't do what you need unfortunately. But I've never run into a situation where I've had to do this. I think you may need to think about alternative approaches to your solution. This is why I was trying to inquiry to find more details about your specific situation.
A scenario that this might be valid: there are additional tools not in repository, but downloaded using NuGet, I don't want to import the tasks until they are ready.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.