Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Conditionals in ItemGroup in csproj files not working properly #7417

@wilbaker

Description

@wilbaker

The same issue was report in #4928 (which I am unable to re-open), and I just hit this issue in VS for Mac 8.0.3 (build 14).

The following does not work in VS for Mac (but works with VS for Windows and when building from the command line with dotnet build).

  <ItemGroup Condition="'$(IsOSX)' == 'true'">
    <ProjectReference Include="..\GVFS.Platform.Mac\GVFS.Platform.Mac.csproj" />
    <Compile Include="..\GVFS.PlatformLoader\PlatformLoader.Mac.cs">
      <Link>PlatformLoader.Mac.cs</Link>
    </Compile>
  </ItemGroup>

  <ItemGroup Condition="'$(OS)' == 'Windows_NT'">
    <ProjectReference Include="..\GVFS.Platform.Windows\GVFS.Platform.Windows.csproj" />
    <Compile Include="..\GVFS.PlatformLoader\PlatformLoader.Windows.cs">
      <Link>PlatformLoader.Windows.cs</Link>
    </Compile>
  </ItemGroup>

VS for Mac will end up including both ProjectReferences and PlatformLoader source files:

image

As a work around I've switched to using Choose/When:

  <Choose>
    <When Condition="'$(OS)' == 'Windows_NT'">
      <ItemGroup>
        <ProjectReference Include="..\GVFS.Platform.Windows\GVFS.Platform.Windows.csproj" />
        <Compile Include="..\GVFS.PlatformLoader\PlatformLoader.Windows.cs">
          <Link>PlatformLoader.Windows.cs</Link>
        </Compile>
      </ItemGroup>
    </When>
    <Otherwise>
      <ItemGroup>
        <ProjectReference Include="..\GVFS.Platform.Mac\GVFS.Platform.Mac.csproj" />
        <Compile Include="..\GVFS.PlatformLoader\PlatformLoader.Mac.cs">
          <Link>PlatformLoader.Mac.cs</Link>
        </Compile>
      </ItemGroup>
    </Otherwise>
  </Choose>

(See microsoft/VFSForGit#1060)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions