.NET Framework Bookmark and Share   
 index > MSBuild > Conditional file include based on a conditional compilation symbol
 

Conditional file include based on a conditional compilation symbol

Hi All,


Howdo I include a file into a Visual Studio Project only if the project's "conditional compilation symbols" include the RETAIL one ?

We need to use this withMSBuild.


Thanks in advance,

Alberto
devdept
Hi Alberto,

Please first download msbuild extension pack at http://www.msbuildextensionpack.com/

Importing its tasks, then use the following task:

<MSBuild.ExtensionPack.Framework.TextString TaskAction="Compare" Comparison="Contains" String1="$(DefineConstants)" String2="RETAIL" IgnoreCase="false">
<Output PropertyName="IsRetail" TaskParameter="Result"/>
</MSBuild.ExtensionPack.Framework.TextString>

<ItemGroup> 
<Compile Include="FolderName\File.ext" Condition="$(IsRetail) == true" /> 
</ItemGroup> 


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Marked As Answer bydevdept Wednesday, September 23, 2009 7:11 AM
  •  
Hongye Sun
Hi Alberto,

In VS project, the conditional compilation symbols are defined as:

<

DefineConstants>TRACE;DEBUG;RETAIL</DefineConstants>

In MSBuild 3.5, you have to use other task to parse the text in the property. Please take a look at:
http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/827eb72a-65fb-426c-862c-6095f71bd4bc

Hongye Sun [MSFT]

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Hongye Sun
Thanks Hongye,


Suppose you have the following item group in the visual studio project listing:

<ItemGroup> 

<Compile Include="FolderName\File.ext" /> 

</ItemGroup> 



What shall we add to include it only if the following includes the RETAIL symbol?


<DefineConstants>TRACE;DEBUG;RETAIL</DefineConstants>


Thanks,

Alberto
devdept
Hi Alberto,

Please first download msbuild extension pack at http://www.msbuildextensionpack.com/

Importing its tasks, then use the following task:

<MSBuild.ExtensionPack.Framework.TextString TaskAction="Compare" Comparison="Contains" String1="$(DefineConstants)" String2="RETAIL" IgnoreCase="false">
<Output PropertyName="IsRetail" TaskParameter="Result"/>
</MSBuild.ExtensionPack.Framework.TextString>

<ItemGroup> 
<Compile Include="FolderName\File.ext" Condition="$(IsRetail) == true" /> 
</ItemGroup> 


Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Marked As Answer bydevdept Wednesday, September 23, 2009 7:11 AM
  •  
Hongye Sun
Importing its tasks, then use the following task:

What do you mean with "importing" ?


Thanks,

Alberto
devdept
Using a task by UsingTask element
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
Hongye Sun
Thanks again,

Alberto
devdept

You can use google to search for other answers

Custom Search

More Threads

• how to pass item to msbuild task
• SmtpMail Task Impl
• ApplicationVersion ignored on ClickOnce publish
• New Microsoft SDC Tasks Release (2.1.3009.0)
• Web Setup Project Build Error
• Update Assembly Version without modifying assemblyInfo.cs
• "Microsoft.Sdc.Tasks" project is not getting recognized
• What is the BuildUri in the Get Task?
• Matching up items in multiple item lists
• synchronize two folders during deployment