dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

System.PlatformNotSupportedException when parsing solution in mono #2554

Open ngyukman opened 6 years ago

ngyukman commented 6 years ago

It's failing the test case in mono environment, by tracing the code I couldn't find where it could throw such exception in BuildEnvironmentHelper. Any help is appreciated Changes related: https://github.com/Ullink/gradle-msbuild-plugin/pull/77

https://travis-ci.org/Ullink/gradle-msbuild-plugin/builds/279544693?utm_source=github_status&utm_medium=notification

Exception detail:


System.PlatformNotSupportedException : Operation is not supported on this platform.
  at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance () [0x00017] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Shared.NativeMethodsShared.get_IsMono () [0x00033] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.BackEnd.Logging.LoggingService..ctor (Microsoft.Build.BackEnd.Logging.LoggerMode loggerMode, System.Int32 nodeId) [0x00039] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.BackEnd.Logging.LoggingService.CreateLoggingService (Microsoft.Build.BackEnd.Logging.LoggerMode mode, System.Int32 node) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection.CreateLoggingService (System.Int32 maxCPUCount, System.Boolean onlyLogCriticalEvents) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.Collections.Generic.IEnumerable`1[T] loggers, System.Collections.Generic.IEnumerable`1[T] remoteLoggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations, System.Int32 maxNodeCount, System.Boolean onlyLogCriticalEvents) [0x0011d] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.Collections.Generic.IEnumerable`1[T] loggers, Microsoft.Build.Evaluation.ToolsetDefinitionLocations toolsetDefinitionLocations) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 
  at Microsoft.Build.Evaluation.ProjectCollection..ctor (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties) [0x00000] in <5452a999769d4e6a81de7a3aa0b8f9f1>:0 ```
mrgleba commented 6 years ago

I think https://github.com/Microsoft/msbuild/commit/9654902b70e22eccc8105efdac5060c7d7adaa1a#diff-7dd0925e4fa31af6856e773c2c80a62c broke the IsMono on Linux.

As a part of caching it's running now BuildEnvironmentHelper.Initialize() which in turn does a PInvoke in VisualStudioLocationHelper which throws on Linux.

I think this is currently a blocking issue for omnisharp on linux: https://github.com/OmniSharp/omnisharp-roslyn/issues/1008

akoeplinger commented 6 years ago

Hmm, we're not hitting this issue with the msbuild we bundle in Mono, though I'm not sure why as it looks like we should 😄

@radical ?

VitaliLiashchuk commented 5 years ago

I experience same issue while execute method OpenSolutionAsync from MSBuildWorkspace class under MacOS...

eatdrinksleepcode commented 5 years ago

I am hitting this while running the Microsoft.Build NuGet package (versions 15.6.85 and 15.9.20) with Mono 5.18.0 on OSX. As @akoeplinger said, I do not get the same error with the Microsoft.Build bundled with Mono.

Any update, or possible fix coming?

mauricereeves commented 5 years ago

I'm also experiencing this on OSX using the Microsoft.Build.NuGet packages (version 15.9.20) with mono 5.18.0.268.

akoeplinger commented 5 years ago

@radical do you know if there's a simple fix from our fork we could upstream for this?

ngyukman commented 5 years ago

I remember the problem was TryFromVisualStudioProcess in https://github.com/Microsoft/msbuild/blob/master/src/Shared/BuildEnvironmentHelper.cs

but I don't remember exactly how it would throw it In the end I did a hack by skipping the check in BuildEnvironmentHelper.Instance.RunningInVisualStudio https://github.com/Ullink/gradle-msbuild-plugin/blob/master/src/main/dotnet/ProjectFileParser/MonoHack.cs

so removing the call of RunningInVisualStudio should fix the issue

eatdrinksleepcode commented 5 years ago

Are there any plans for making some progress on this? I have looked at the code, but there are clearly intended impacts on a number of different scenarios, and without knowing what all of those are and the ability to test them, it's not something I can fix myself.

Migrating my open source project to .NET Core has been blocked on this for 3 months...

coolbluewater commented 4 years ago

Hi, is there a workaround for this? This causes a crash while instantiating an MSBuildWorkspace on Mac, so it seems like it ought to be considered a high-severity bug.

@DustinCampbell, could you please weigh in on this one? It has been open for 3 years. I ran into it while using Visual Studio for Mac to build CodeConverter (see the link just above this comment box).