Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
theolivenbaum opened this issue Nov 11, 2020 · 15 comments
Closed

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

theolivenbaum opened this issue Nov 11, 2020 · 15 comments
Labels
bug needs-triage Have yet to determine what bucket this goes in.

Comments

@theolivenbaum
Copy link

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?

@theolivenbaum theolivenbaum added bug needs-triage Have yet to determine what bucket this goes in. labels Nov 11, 2020
@theolivenbaum theolivenbaum changed the title Bug when using MSBuild since NET5.0 Bug when using MSBuild with custom target since NET5.0 update Nov 11, 2020
@benvillalobos
Copy link
Member

Team Triage: Can you confirm the versions of MSBuild and SDK you"re using? It sounds like you"re using an older MSBuild with a newer SDK.

@theolivenbaum
Copy link
Author

theolivenbaum commented Nov 11, 2020 via email

@benvillalobos
Copy link
Member

Very strange, can you post the output of dotnet msbuild --version from your 5.0.100 sdk?

I can"t seem to repro it from sdk version 5.0.100-rc.2.20479.15 that"s using MSBuild version 16.8.0-preview-20475-05+aed5e7ed0

@jibsaramnim
Copy link

I"m getting the same issue for a project that is targeting net45:

/usr/share/dotnet/sdk/5.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(5,5): Error MSB4186: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkIdentifier("$(TargetFramework)")". Method "[MSBuild]::GetTargetFrameworkIdentifier" 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. (MSB4186) (SMAPI.ModBuildConfig.Analyzer)
/usr/share/dotnet/sdk/5.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(5,5): Error MSB4186: Invalid static method invocation syntax: "[MSBuild]::GetTargetFrameworkIdentifier("$(TargetFramework)")". Method "[MSBuild]::GetTargetFrameworkIdentifier" 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. (MSB4186) (SMAPI.Toolkit.CoreInterfaces)
> dotnet --version
5.0.100
> msbuild -version
16.6.0.32601%

The Project Options view in Monodevelop (7.8.4 (build 2)) actually shows the same oddness:
image

@emmanuel128
Copy link

emmanuel128 commented Nov 12, 2020

Hi,

I"m getting the same error as @hellodeibu on Visual Studio for Mac. I have a project is targeting net48 and the Xamarin project is targeting netstandard2.0.

Does anyone have a solution?

Edit:

  • dotnet -- version : 5.0.100
  • msbuild --version : 16.6.0

@benvillalobos
Copy link
Member

@emmanuel128 @hellodeibu could you post specifically your dotnet msbuild --version? Info? As typically msbuild -version points to the msbuild installed by visual studio rather than the msbuild packed along with the sdk

@jibsaramnim
Copy link

jibsaramnim commented Nov 13, 2020

@benvillalobos apologies for not including that too:

> dotnet --version
5.0.100
> msbuild -version
16.6.0.32601%
> dotnet msbuild -version
16.8.0.52002% 

Just in case this helps too: this is on Ubuntu 20.04 and with MonoDevelop 7.8.4 (build 2) installed.

Edit: small addendum; I had completely removed and re-installed mono-related packages a few times, trying out different repositories and versions and whatnot. I ended with the nightly repository but I don"t think there"s anything in there that"s newer than whatever is in preview. I had the same results (failed to build, Monodevelop showing that odd string, etc.) with the stable-bionic source (stable-focal does not yet contain Monodevelop).

I have removed and re-installed everything mono related from stable-bionic and I"m getting the same versions as shown above.

@theolivenbaum
Copy link
Author

theolivenbaum commented Nov 13, 2020

Same here, using the latest stable release of VS2019 Enterprise on Windows:

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.8.0
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

>msbuild -version
Microsoft (R) Build Engine version 16.8.1+bd2ea1e3c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.8.1.52902
>dotnet msbuild -version
Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

16.8.0.52002
>dotnet --version
5.0.100

Also in my case this happens when calling MSBuild programmatically with the h5 compiler.

@benvillalobos
Copy link
Member

We"re curious if this may be a GAC issue. Please try repairing Visual Studio. This will at least eliminate that possibility.

@benvillalobos
Copy link
Member

For those on Mono, this might be because Mono needs to be updated. Here is an issue tracking this: mono/mono#20250

@theolivenbaum
Copy link
Author

Not Mono on my case as running on Windows. Already tried the VS repair but didn"t fix it either.

And same issue happens when running dotnet build on linux so don"t think it"s the case.

@benvillalobos
Copy link
Member

Tried to repro again and not seeing any issues:

dotnet msbuild -version

Microsoft (R) Build Engine version 16.8.0+126527ff1 for .NET       
Copyright (C) Microsoft Corporation. All rights reserved.

16.8.0.52002

dotnet --version

5.0.100

@theolivenbaum could you try building a tiny project (via dotnet build on 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:

<Project>
<PropertyGroup>
    <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
    <TargetPlatformIdentifier>h5</TargetPlatformIdentifier>
    <TargetPlatformVersion>2.0</TargetPlatformVersion>
</PropertyGroup>
  <PropertyGroup>
    <TargetFrameworkIdentifier>$([MSBuild]::GetTargetFrameworkIdentifier("$(TargetFramework)"))</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v$([MSBuild]::GetTargetFrameworkVersion("$(TargetFramework)", 2))</TargetFrameworkVersion>
  </PropertyGroup>

  <Target Name="HelloWorld">
    <Message Text="Hello World!" Importance="High"/>
  </Target>
</Project>

Note that this does fail with your error if I global.json myself to do 3.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:

  1. Providing a minimal repro of your specific scenario.
  2. Providing binlogs of your build.

@theolivenbaum
Copy link
Author

Hi @benvillalobos

Tried to reproduce the issue today - but I"m not seeing it anymore, even when reverting the recent commits on the h5 compiler and SDK targets. Wondering if the update to VS 2019 16.8.1 that came immediately after 16.8.0 fixed the problem meanwhile and this was indeed a GAC cache issue...

@benvillalobos
Copy link
Member

benvillalobos commented Nov 18, 2020

@theolivenbaum It happens 🙂 Edit: The PR that fixed this automatically unGAC"s MSBuild assemblies at install/repair time. #5626

Closing this issue out. For those running on mono, see this issue: mono/mono#20250

@granadacoder
Copy link

granadacoder commented Mar 9, 2021

For future readers.

(On a Mac).

I updated (added) (only) dotnetcore SDK 5.0, and started getting this error.

error msb4186: invalid static method invocation syntax: "[msbuild]::gettargetframeworkidentifier("$(targetframework)")". method "[msbuild]::gettargetframeworkidentifier" 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. (msb4186)

Our work machines are fairly "locked down", so I do these upgrades one by one to easy trouble shooting if anything goes wrong.

Below image was what was shown when I did a "upgrade" (aka, below is the newer version at the time of writing)
Unfortunately, I did not capture the original version.

image

After I did a Visual Studio Update (March 2021 timeline (again, above image)), I opened up my solution, and everything was ok in the nuget restore world.

Below is the complete "About VS" information... of the later-working version of VS.

I still have a few not-yet-done upgrades....but some of those are outside of the project-types I work on.

`
=== Visual Studio Community 2019 for Mac ===

Version 8.9 (build 1651)
Installation UUID: c07d044a-1db9-425d-9292-732fd7272960
GTK+ 2.24.23
Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000090

=== Mono Framework MDK ===

Runtime:
Mono 6.12.0.90 (2020-02/d3daacdaa80) (64-bit)
Package version: 612000090

=== Roslyn (Language Service) ===

3.9.0-5.21112.8+f3ff04378c972d435826e6181de364b3c0db8d14

=== NuGet ===

Version: 5.8.0.6860

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.103/Sdks
SDK Versions:
5.0.103
3.1.406
3.1.401
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
5.0.3
3.1.12
3.1.7
2.1.21

=== .NET Core 3.1 SDK ===

SDK: 3.1.406

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin Designer ===

Version: 16.9.0.316
Hash: bd2705417
Branch: remotes/origin/d16-9
Build date: 2021-02-24 00:16:08 UTC

=== Apple Developer Tools ===

A valid Xcode installation was not found at the configured location: "/Library/Developer/CommandLineTools"

=== Xamarin.Mac ===

Version: 6.20.2.2 (Visual Studio Community)
Hash: 817b6f72a
Branch: d16-7
Build date: 2020-07-18 18:44:59-0400

=== Xamarin.iOS ===

Version: 13.20.2.2 (Visual Studio Community)
Hash: 817b6f72a
Branch: d16-7
Build date: 2020-07-18 18:45:00-0400

=== Xamarin.Android ===

Version: 11.0.2.0 (Visual Studio Community)
Commit: xamarin-android/d16-7/025fde9
Android SDK: Not found

=== Microsoft OpenJDK for Mobile ===

Java SDK: Not Found

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.9.0.22
Hash: a391de2
Branch: remotes/origin/d16-9
Build date: 2021-02-18 03:14:56 UTC

=== Android Device Manager ===

Version: 16.9.0.17
Hash: fc2b3db
Branch: remotes/origin/d16-9
Build date: 2021-02-18 03:15:18 UTC

=== Build Information ===

Release ID: 809001651
Git revision: c05b1dec4362b5956d47624a437e900ffdc9aa0a
Build date: 2021-02-25 11:27:51-05
Build branch: release-8.9
Xamarin extensions: c05b1dec4362b5956d47624a437e900ffdc9aa0a

=== Operating System ===

Mac OS X 10.15.7
Darwin 19.6.0 Darwin Kernel Version 19.6.0
Tue Jan 12 22:13:05 PST 2021
root:xnu-6153.141.16~1/RELEASE_X86_64 x86_64

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-triage Have yet to determine what bucket this goes in.
Projects
None yet
Development

No branches or pull requests

5 participants