Execute different commands in MSBuild depending on platform

November 20, 2020 msbuild

Another quick snippet that shows how to change what command will be executed in MSBuild based on the OS the script is running on.

<Target Name="GenerateFiles" BeforeTargets="CoreGenerateAssemblyInfo">
  <PropertyGroup>
    <_GenerateFilesCommand Condition="'$(OS)' == 'Windows_NT'">foo.exe</_GenerateFilesCommand>
    <_GenerateFilesCommand Condition="'$(OS)' == 'Unix'">mono foo.exe</_GenerateFilesCommand>
  </PropertyGroup>
  
  <Exec Command="$(_GenerateFilesCommand)" />
</Target>