Skip to content

Bug when using MSBuild with custom target since NET5.0 update #5875

@theolivenbaum

Description

@theolivenbaum

Issue Description

I'm hitting a bug when consuming a custom project SDK target (http://nuget.org/packages/h5.target):

Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)', 2)". Method '[MSBuild]::GetTargetFrameworkVersion' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). Check that all parameters are defined, are of the correct type, and are specified in the right order.  C:\Program Files\dotnet\sdk\5.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets

The code in the targets file that seems to be triggering this issue is the following:

  <PropertyGroup Condition="'$(TargetFramework)' != '' and ('$(TargetFrameworkIdentifier)' == '' or '$(TargetFrameworkVersion)' == '')">

    <TargetFrameworkIdentifier>$([MSBuild]::GetTargetFrameworkIdentifier('$(TargetFramework)'))</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)', 2))</TargetFrameworkVersion>
  </PropertyGroup>

If I manually force the properties to the expected (or dummy) values, so that we avoid the GetTargetFrameworkIdentifier, GetTargetFrameworkVersion, GetTargetPlatformIdentifier and GetTargetPlatformVersion calls above:

    <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <TargetPlatformIdentifier>h5</TargetPlatformIdentifier>
    <TargetPlatformVersion>2.0</TargetPlatformVersion>

Then the compilation using MSBuild works fine.

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triageHave yet to determine what bucket this goes in.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions