Select single item from wildcard ItemGroup in msbuild

370 Views Asked by At

I am trying to create a property in a MsBuild file, using ItemGroup. The property needs to be the path to an executable which is "restored" by a nuget update command. The problem is that I don't know beforehand where the file will end up (as the nuget update will get the latest version) and there is the possibility of having multiple of them (apparently nuget may forget to delete the old package folder).

What I have tried so far is this:

<ItemGroup>
    <Executable Include="packages\mypackage*\**\myexecutable.exe" />
</ItemGroup>

and it is used as such:

<Exec Command="$(Executable) $(MSBuildThisFileDirectory)solutionfile.sln $(MSBuildThisFileDirectory)solutionfile.zip" WorkingDirectory="$(MSBuildThisFileDirectory)" />

I need the wildcard to find the file and everything works ok except when there are multiple versions, where the Executable item becomes this:

packages\mypackage-1.0\myexecutable.exe;packages\mypackage-2.0\myexecutable.exe;

Clearly ItemGroup is finding both and creating a ;-separated list. I need a way to exclude everything and keep only one... or even a better idea on how to achieve what I need through MsBuild (if possible something that does not imply creating a custom task or just writing a separate script).

Thanks!

0

There are 0 best solutions below