Skip to content

Sdk.Targets - Use GetTargetFrameworkIdentifier to identify framework. #19

@TheBrambleShark

Description

@TheBrambleShark

Example Input:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <NetFx>net461</NetFx>
        <NetStandard>netstandard2.0</NetStandard>
        <NetCoreApp>netcoreapp3.0</NetCoreApp>
        <NetCore>net5.0</NetCore>
    </PropertyGroup>

    <Target Name="MyTarget">
        <Message Importance="high" Text="$(NetFx) = $([MSBuild]::GetTargetFrameworkIdentifier($(NetFx)))" />
        <Message Importance="high" Text="$(NetStandard) = $([MSBuild]::GetTargetFrameworkIdentifier($(NetStandard)))" />
        <Message Importance="high" Text="$(NetCoreApp) = $([MSBuild]::GetTargetFrameworkIdentifier($(NetCoreApp)))" />
        <Message Importance="high" Text="$(NetCore) = $([MSBuild]::GetTargetFrameworkIdentifier($(NetCore)))" />
    </Target>

</Project>

Example Output:

net461 = .NETFramework
netstandard2.0 = .NETStandard
netcoreapp3.0 = .NETCoreApp
net5.0 = .NETCoreApp

API Proposal:

<PropertyGroup>
  <RemoraFrameworkIdentifier>$([MSBuild]::GetTargetFrameworkIdentifier($TargetFramework))</RemoraFrameworkIdentifier>
  <IsNET>$(RemoraFrameworkIdentifier) == '.NETCoreApp'</IsNET>
  <IsNETCore>$(RemoraFrameworkIdentifier) == '.NETCoreApp'</IsNETCore>
  <IsNETStandard>$(RemoraFrameworkIdentifier) == '.NETStandard'</IsNETStandard>
  <IsNETFramework>$(RemoraFrameworkIdentifier) == '.NETFramework'</IsNETFramework>
  <IsRunnableTarget>$(RemoraFrameworkIdentifier) != '.NETStandard'</IsRunnableTarget>
</PropertyGroup>

Drawbacks:
We lose differentiation between IsNET and IsNETCore. I'm not too entirely sure what IsNET is used for though - MSBuild doesn't appear to differentiate between netcoreapp3.0 and net5. Additionally, it doesn't appear to be used within the SDK at all. Is this intended for use by consumers of the SDK?

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