cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.89k stars 725 forks source link

After updating VS 2017 to 15.6.3: Could not load type 'Microsoft.Build.Logging.ProfilerLogger' #2091

Open tompazourek opened 6 years ago

tompazourek commented 6 years ago

I just updated to latest version of Visual Studio 2017 (15.6.3) that was just released and my Cake builds started crashing (when restoring NuGet packages or running the build task).

This is the snippet of the log:

MSBuild auto-detection: using msbuild version '15.6.82.30579' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin'.

Unhandled Exception: System.TypeLoadException: Could not load type 'Microsoft.Build.Logging.ProfilerLogger' from assembly 'Microsoft.Build, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at System.Signature.GetSignature(Void* pCorSig, Int32 cCorSig, RuntimeFieldHandleInternal fieldHandle, IRuntimeMethodInfo methodHandle, RuntimeType declaringType)
   at System.Reflection.RuntimeMethodInfo.FetchNonReturnParameters()
   at System.Reflection.RuntimeMethodInfo.GetParameters()
   at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
   at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Exception.GetStackTrace(Boolean needFileInfo)
   at System.Exception.ToString(Boolean needFileLineInfo, Boolean needMessage)
   at System.Exception.ToString()
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main()

I'm using Cake 0.26.1 and building on Windows 10, it's a full .NET Framework 4.7.1 app, old csproj structure.

I get the error from running NuGetRestore(solutionFile), but also from running MSBuild(solutionFile, ...).

Is this a Cake issue, or should I look for help somewhere else? Can you help?

Thanks for your time.


EDIT: The only other mention of this error I Googled is:

https://developercommunity.visualstudio.com/content/problem/214894/vs-2017-update-v1561-v1562-msbuild-crashes.html

patriksvensson commented 6 years ago

@tompazourek Doesn't sound like a Cake issue, but hard to know without the actual build script. Can you run the build with diagnostic verbosity and paste the build log here? Thanks.

tompazourek commented 6 years ago

@patriksvensson Thanks for getting back to me. Unfortunately, I'm afraid I cannot assist more at this point because I decided to uninstall Visual Studio 15.6.3 and revert back to an older version again. I really needed to get some work done, and this was the only solution.

Maybe somebody else will experience the same issue and will follow up with more information; the 15.6.3 is a brand new release, and it's possible that more people will have the same issue when they update. Or I may try updating to 15.6.3 again when I've got a bit more time to experiment to pinpoint this issue.

In the meantime, there's some more development related to this in the mentioned Visual Studio Developer Community ticket. Right now, it looks like it might be solved by removing some MSBuild assemblies from the GAC.

marcinsmialek commented 6 years ago

@patriksvensson It looks like a conflict between Cake tool selection and how VS was installed

I was getting similar issue with Cake 0.30 and VS 15.8.3 with a csproj, which has a custom task from dll. The said task references Microsoft.Build.Framework. Running raw MSBuild with sln = no issues Running cake with 1-liner task results in an error:

Task("Default")
.Does(() =>
{
MSBuild("./s.sln");
});

Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

It's similar to this: https://stackoverflow.com/questions/43330915/could-not-load-file-or-assembly-microsoft-build-frameworkvs-2017

If I add Microsoft.Build.Framework to GAC, it works fine, but it's something I'd like to avoid, especially as raw MSBuild worked just fine.

When I add this line to csproj: <Message Text="MSBuildBinPath = $(MSBuildBinPath)"/> with raw MSBuild it shows:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin

with Cake:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64

If I add C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64 in the beginning of my PATH environment variable, I'm getting exactly the same issue with msbuild as with Cake

Using such settings modifier fixes this issue in my case: settings.SetMSBuildPlatform(MSBuildPlatform.x86)

Before using Cake, I used this PS snippet to get MSBuild path (yes, always x86) Join-Path (&'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' -latest -requires Microsoft.Component.MSBuild -property installationPath) 'Bin\MSBuild.exe'

This in fact may be related to (and solved by) this (+ the mentioned GAC issue): https://github.com/cake-build/cake/issues/424

devlead commented 6 years ago

VSWHere can be used with cake too https://cakebuild.net/blog/2017/03/vswhere-and-visual-studio-2017-support