14

How can I determine if a project is build in Debug (or Release) mode within an MSBuild .targets file and use this information as a condition for another property?

Something like:

<OutDir Condition="IsDebug">bin\Debug\$(SomeOtherProperty)\</OutDir>
<OutDir Condition="!IsDebug">bin\Release\$(SomeOtherProperty)\</OutDir>

Is there such thing as Debug/Release mode, or are they just conventional names for different sets of configuration properties' values?

1 Answer 1

25

Debug/Release or whatever are just conventional values for the Configuration property.

So, as long the project that includes/calls your .targets file adheres to the convention; you can check for debug mode as follows:

<OutDir>bin\Release\$(SomeOtherProperty)\</OutDir>
<OutDir Condition=" '$(Configuration)' == 'Debug' ">bin\Debug\$(SomeOtherProperty)\</OutDir>

or you could just use that variable directly:

<OutDir>bin\$(Configuration)\$(SomeOtherProperty)\</OutDir>
2
  • Well the problem is that I have 8 configurations, half debug and half release. Their names of course are not 'Debug' or 'Release' but conventionally i have named them 'Debug <something>' 'Debug <somethingElse>' etc. So instead of a == check I would probably do a Contains check right? Commented Dec 27, 2013 at 13:16
  • 1
    Exactly. Depending on the complexity of your targets file, it may be useful to either introduce the IsDebug property from your example, or an ConfigurationType (or similar) property having the value Debug or Release. Commented Dec 27, 2013 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.