Skip to content

Instantly share code, notes, and snippets.

@wilhelmberg
Last active April 30, 2019 17:53
Show Gist options
  • Save wilhelmberg/4eb166010e995513d308fbb0feabfe35 to your computer and use it in GitHub Desktop.
Save wilhelmberg/4eb166010e995513d308fbb0feabfe35 to your computer and use it in GitHub Desktop.
cross platform msbuild configuration
  • Porting MSBuild Projects To XBuild

    <NuGetCommand Condition=" '$(NuGetCommand)'=='' AND '$(OS)' == 'Windows_NT'">"$(NuGetExe)"</NuGetCommand>
    <NuGetCommand Condition=" '$(NuGetCommand)'=='' AND '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 "$(NuGetExe)"</NuGetCommand>
  • Cross Platform Builds on Windows and Mono with MSBuild

    <Reference Include="Windows.Specific.dll" Condition=" '$(OS)' != 'Unix' "/>
    <Reference Include="NonWindows.Specific.dll" Condition=" '$(OS)' == 'Unix' "/>

Problems detecting OS in MSBuild/xbuild

  • MSBuilds has: $(OS) -> OSX/Unix/Windows_NT EDIT!! OSX seem to have been removed recently: dotnet/msbuild#538
  • xbuild only has: $(OS) -> Unix/Windows_NT, on Mac it also evaluates to Unix

[RFC] Detecting current OS in targets:

MSBuild sets the $(OS) property to OSX/Unix/Windows at runtime, which can be used in targets to determine the current OS. But xbuild has been using $(OS)==Unix on OSX and Linux, because of an old mono bug. And it continues to do so for compatibility reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment