Skip to content

Instantly share code, notes, and snippets.

@jonpryor
Last active February 22, 2017 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonpryor/661edf823539c06cb4cce9ccb4c8ab47 to your computer and use it in GitHub Desktop.
Save jonpryor/661edf823539c06cb4cce9ccb4c8ab47 to your computer and use it in GitHub Desktop.

Consider this scenario:

  1. You have expansion-deps.projitems which contains the @(JdkIncludePath) item group.
  2. You have expansion.props which uses @(JdkIncludePath) to generate a $(_JdkIncludePaths) property
  3. You have expansion.projitems which creates a new @(_HostRuntime) item group which uses $(JdkIncludePath) within the %(_HostRuntime.CFlags) item metadata
  4. You print out %(_HostRuntime.CFlags).

Incredibly, behavior differs between xbuild, msbuild in mono 4.6, and msbuild in mono 4.8.

With xbuild (all versions) the value of $(_JdkIncludePaths) is printed:

$ xbuild /v:minimal expansion.targets 
XBuild Engine Version 14.0
Mono, Version 4.8.0.0
Copyright (C) 2005-2013 Various Mono authors
	CFlags: works-with-mono-4.6: -I/something -I/something-else
	CFlags: works-with-mono-4.8: -I/something -I/something-else

With msbuild from Mono 4.6, the value of $(_JdkIncludePaths) is printed. (TODO: obtain actual output.)

With msbuild from Mono 4.8, the value of $(_JdkIncludePaths) is not printed:

$ msbuild /v:minimal expansion.targets 
Microsoft (R) Build Engine version 15.1.0.0
Copyright (C) Microsoft Corporation. All rights reserved.

  CFlags: works-with-mono-4.6: 
  CFlags: works-with-mono-4.8: -I/something -I/something-else

The %(_HostRuntime.CFlags) value for works-with-mono-4.8 doesn't use $(_JdkIncludePaths). Instead, it uses @(JdkIncludePath):

    <_HostRuntime Include="works-with-mono-4.8">
      <CFlags>@(JdkIncludePath->'-I%(Identity)', ' ')</CFlags>
    </_HostRuntime>

Of course, the canonical version is...what's MSBuild on Windows output? MSBuild/Windows matches xbuild:

>msbuild /v:minimal expansion.targets
Microsoft (R) Build Engine version 14.0.24730.2
Copyright (C) Microsoft Corporation. All rights reserved.

  CFlags: works-with-mono-4.6:  -I/something -I/something-else
  CFlasg: works-with-mono-4.8:  -I/something -I/something-else
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<JdkIncludePath Include="/something" />
<JdkIncludePath Include="/something-else" />
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<_HostRuntime Include="works-with-mono-4.6">
<CFlags>$(_JdkIncludePaths)</CFlags>
</_HostRuntime>
<_HostRuntime Include="works-with-mono-4.8">
<CFlags>@(JdkIncludePath->'-I%(Identity)', ' ')</CFlags>
</_HostRuntime>
</ItemGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_JdkIncludePaths>@(JdkIncludePath->'-I%(Identity)', ' ')</_JdkIncludePaths>
</PropertyGroup>
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="expansion-deps.projitems" />
<Import Project="expansion.props" />
<Import Project="expansion.projitems" />
<Target Name="Build">
<Message Importance="High" Text="CFlags: %(_HostRuntime.Identity): %(_HostRuntime.CFlags)" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment