1

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!

Tallmaris
  • 7,605
  • 3
  • 28
  • 58
  • 1
    *I need a way to exclude everything and keep only one...* which one? – stijn Nov 21 '17 at 16:07
  • Is the package in your control? I'd suggest including an msbuild file in the NuGet package that sets a property to the path of the executable which is then available in all projects that reference the nuget package. Then the individual projects don't have to add any logic to find the executable. – Martin Ullrich Nov 21 '17 at 18:40
  • @stijn indeed good question... it should be the latest installed, or even the first found would be ok. Martin Ullrich, can you put an answer? I'll try that out. – Tallmaris Nov 24 '17 at 14:10

0 Answers0