Marien Monnier
Marien Monnier

Reputation: 205

MSBuild - Create a property with wildcards?

I'm currently moving my project to Visual Studio 2012 and start using nuget. So I'll use the "NUnit Runners" nuget package instead of a nunit library.

The problem being that nuget creates folders with the package version. For example, NUnit Runners is inside the folder: src\packages\NUnit.Runners.2.6.1\

Until now, Nunit was inside my lib\NUnit folder. So, inside my MSBuild file, I was executing the tests by specifying the path:

<PropertyGroup>
    <NUnitFolder>$(MSBuildProjectDirectory)\lib\NUnit</NUnitFolder>
</PropertyGroup>
<NUnit Assemblies="..." ToolPath="$(NUnitFolder)" />

But I don't want to have to specify a version number inside my msbuild task, that I would have to update everytime NUnit.Runners is updated.

I tried to play around with CreateProperty, but it doesn't seem to accept wildcards. I also tried ItemGroup, but it works for a list of files, not a folder.

Upvotes: 2

Views: 435

Answers (1)

Marien Monnier
Marien Monnier

Reputation: 205

In the end, instead of trying to create a property with a wildcard, in my case I retrieved the version of NUnit.Runners from the packages.config file.

I now have a Target like this:

<Target Name="GetNUnitFolder">
    <!-- Retrieves the version of NUnit.Runners from the solution's packages.config file -->
    <XmlRead Namespace=""
             XPath="packages/package[@id='NUnit.Runners']/@version"
             XmlFileName="$(MSBuildProjectDirectory)\src\.nuget\packages.config">
        <Output TaskParameter="Value" PropertyName="NUnitVersion" />
    </XmlRead>

    <CreateProperty Value="$(MSBuildProjectDirectory)\src\packages\NUnit.Runners.$(NUnitVersion)\tools">
        <Output TaskParameter="Value" PropertyName="NUnitFolder" />      
    </CreateProperty>
</Target>

Note: to be able to use XmlRead, you need the MSBuildCommunityTasks.

And once I have the version, I rebuild my NUnitFolder property.

Upvotes: 2

Related Questions