Skip to content

[BuildCheck Suggestion]: Detect and flag usage of the $(OS) MSBuild Property #10707

Open
@baronfel

Description

@baronfel

Summary

This property only has two documented values, "Windows_NT" and "Unix", but this doesn't tell the story accurately today. In addition, this property like all properties can be overridden by environment variables. We should guide users to better-supported mechanisms for determining the OS of the executing build. Users should use the static members of the System.OperatingSystem like IsWindows() to check platform support.

Background and Motivation

We don't have documented guidance for moving away from $(OS), this should help drive that as well.

Sample issue or antipattern that the check should be flagging

This

      <DotNetHostFileName>dotnet</DotNetHostFileName>
      <DotNetHostFileName Condition="'$(OS)' == 'Windows_NT'">dotnet.exe</DotNetHostFileName>

should suggest using

      <DotNetHostFileName>dotnet</DotNetHostFileName>
      <DotNetHostFileName Condition="$([System.OperatingSystem]::IsWindows())">dotnet.exe</DotNetHostFileName>

instead

Sample output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: BuildCheckBuildCheck SuggestionSuggestion for a built in MSBuild analyzer. Label should be applied together with 'Area: BuildCheck'Priority:3Work that is nice to havetriaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions