msbuild: Bug when using MSBuild with custom target since NET5.0 update
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?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 1
- Comments: 15 (7 by maintainers)
Tried to repro again and not seeing any issues:
dotnet msbuild -versiondotnet --version@theolivenbaum could you try building a tiny project (via
dotnet buildon your 5.0.100 sdk) that uses[MSBuild]::GetTargetFrameworkIdentifier? This should eliminate whether it could be MSBuildLocator in your scenario.The project I’m building to try and repro this is simply:
Note that this does fail with your error if I
global.jsonmyself to do3.1.404, which is expected as that version of MSBuild would not have the functions being called.You mentioned MSBuildLocator is finding the correct MSBuild, can you verify this? I ask because this issue (should) only come up if you were using an older MSBuild wth a newer sdk somehow.
What may be the most helpful in this scenario: