Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MSBuild, how to construct a dynamic string from iterating over files in an ItemGroup?

I need to create multiple /testcontainer: parameters to feed into a task that exec's MsTest.

I have the following :

  <ItemGroup>
    <TestFiles Include="$(ProjectPath)\**\UnitTest.*.dll" />
  </ItemGroup>

for each match in TestFiles I would like to build a string like so:

"/testcontainer:UnitTest.SomeLibrary1.dll"
"/testcontainer:UnitTest.SomeLibrary2.dll"
"/testcontainer:UnitTest.SomeLibrary3.dll"

I am trying to use the internals of MSBuild without having to create a custom task, is this possible ?

TIA

like image 289
RyBolt Avatar asked May 04 '10 20:05

RyBolt


People also ask

What are MSBuild items and item types?

MSBuild items are inputs into the build system, and they typically represent files (the files are specified in the Include attribute). Items are grouped into item types based on their element names. Item types are named lists of items that can be used as parameters for tasks. The tasks use the item values to perform the steps of the build process.

Is there a way of batching the items in MSBuild?

MSBuild already had a way of batching the items (as I thought!). Thanks for contributing an answer to Stack Overflow! Please be sure to answer the question. Provide details and share your research!

How do I create an MSBuild project?

Create an MSBuild project 1 Open Visual Studio and create a project.#N#Press Esc to close the start window. Type Ctrl + Q to open the search box, type... 2 Click OK or Create to create the project file. More ...

What is MSBuild in Visual Studio?

MSBuild is the build platform for Microsoft and Visual Studio. This walkthrough introduces you to the building blocks of MSBuild and shows you how to write, manipulate, and debug MSBuild projects. You will learn about: Creating and manipulating a project file. How to use build properties How to use build items.


1 Answers

It really depends on the usage of this afterwards. For example the task that you are sending it to, does it accept in an item list and do you want to invoke it once or multiple times?

If you want to invoke it once then you use the @(...) syntax, and if you want to invoke it many times then you do batching with the %(...) syntax.

To invoke once

<Message Text="Test Files: @(TestFiles->'/testcontainer:%(RecursiveDir)%(Filename)%(Extension)')"/>

To invoke many times

<Message Text="Test Files: /testcontainer:%(TestFiles.RecursiveDir)%(TestFiles.Filename)%(TestFiles.Extension)"/>

More info on batching at http://sedotech.com/Resources#batching

like image 199
Sayed Ibrahim Hashimi Avatar answered Sep 29 '22 08:09

Sayed Ibrahim Hashimi