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
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.
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!
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 ...
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With