Using Command Line Tools 2020.2 with Mono

I just got the prompt to update to Rider 2020.2 which seems to come with some new code inspections as I think I got some new warnings.

So I wanted to update my CI pipeline to also use the new tools (Command Line Tools 2020.2), however I ran into a problem: I'm working on a Godot engine project that uses Mono for the C# code. It seems like the 2020.2 tools no longer run with mono? And even when I install dotnet (which is like 300 MB extra for the docker image for CI) it refuses to find the packages even though my solution file builds perfectly with msbuild. I also tried running dotnet restore on my solution file but that did nothing.

My question is how can I make this work? Was this overlooked that people might want to use the resharper tools with mono? CommandLineTools.Unix.2020.1.4 worked perfectly for my use case.

7 comments
Comment actions Permalink
Official comment

Hello Henri,

Please try to use the --mono parameter to specify the path to the Mono executable, refer to the manual for more details.

Please let me know if it helps.

Comment actions Permalink

Thanks for the suggestion, that gets a bit farther:

$ ./inspectcode.sh --mono=$(which mono) /home/hhyyrylainen/Projects/thrive/Thrive.sln
JetBrains Inspect Code 2020.2
Running in 64-bit mode, .NET runtime 3.1.6 under Unix 5.7.14.200
Configuration: Debug, Platform: Any CPU
MSBuild not found
No files to inspect were found.

Additionally if I try to add toolset to specify the msbuild path, I get this:

$ ./inspectcode.sh --mono=$(which mono) --toolset-path=$(which msbuild) /home/hhyyrylainen/Projects/thrive/Thrive.sln
JetBrains Inspect Code 2020.2
Running in 64-bit mode, .NET runtime 3.1.6 under Unix 5.7.14.200
Warning: Cannot load assembly metadata from: /usr/bin/msbuild
Using toolset version 0.0 from /usr/bin
Configuration: Debug, Platform: Any CPU
Could not load file or assembly '/usr/bin/msbuild'. An attempt was made to load a program with an incorrect format.

--- EXCEPTION #1/2 [BadImageFormatException]
Message = “Could not load file or assembly '/usr/bin/msbuild'. An attempt was made to load a program with an incorrect format.”
ExceptionPath = Root.InnerException
ClassName = System.BadImageFormatException
Data.ThreadLocalDebugInfo = “Open solution”
HResult = COR_E_BADIMAGEFORMAT=WIN32_ERROR_BAD_FORMAT=8007000B
Source = System.Private.CoreLib
BadImageFormat_FileName = /usr/bin/msbuild
StackTraceString = “
at System.Reflection.AssemblyName.nGetFileInformation(String s)
at System.Reflection.AssemblyName.GetAssemblyName(String assemblyFile) in /_/src/System.Private.CoreLib/shared/System/Reflection/AssemblyName.cs:line 155
at JetBrains.Platform.MsBuildHost.Process.MsBuildExternalProcess.<GetProcessStartInfo>b__7_0()
at JetBrains.Util.ILoggerEx.Catch[TValue](ILogger thіs, Func`1 F, ExceptionOrigin origin, LoggingLevel loggingLevel)

--- Outer ---

--- EXCEPTION #2/2 [LoggerException]
Message = “Could not load file or assembly '/usr/bin/msbuild'. An attempt was made to load a program with an incorrect format.”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
InnerException = “Exception #1 at Root.InnerException”
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
at JetBrains.Util.ILoggerEx.LogException(ILogger this, LoggingLevel level, Exception exception, ExceptionOrigin exceptionOrigin, String comment)
at JetBrains.Util.ILoggerEx.Catch[TValue](ILogger thіs, Func`1 F, ExceptionOrigin origin, LoggingLevel loggingLevel)
at JetBrains.Platform.MsBuildHost.Process.MsBuildExternalProcess.GetProcessStartInfo(Int32 port)
at JetBrains.Platform.RdFramework.ExternalProcess.ProtocolExternalProcess`2.CreateProcess(IProtocol protocol, LifetimeDefinition processLifetimeDefinition, StartupOutputWriter outputWriter)
at JetBrains.Platform.RdFramework.ExternalProcess.ProtocolExternalProcess`2.Run()
at JetBrains.Platform.MsBuildHost.MsBuildConnectionFactory.Create(Lifetime lifetime, MsBuildConnectionContext context)
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildSessionHolder.CreateSession()
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildSessionHolder.TryExecute[T](Func`2 executor, T& result)
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildProjectHost.Reload(Lifetime lifetime, IReadOnlyCollection`1 changes, IReloadEventsConsumer reloadEventsConsumer, FileSystemPath logPath)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.Load(ICollection`1 changesToAdd, ICollection`1 changesToUpdate, ICollection`1 changesToRemove, FileSystemPath logPath, ProjectStructureStamp stamp)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.<>c__DisplayClass32_0.<LoadAndSync>b__1()
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.ProjectHostReloadTaskExecutor.Execute(Func`1 executeAction, Action`1 notifyAction, Boolean async)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.BuildSolutionStructure(SolutionStructureChange solutionStructureChange)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.ReloadSolutionInternal(IForceUpdateProjectsPolicy forceUpdateProjectsPolicy)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.ReloadSolution()
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.Init()
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHostManager.SolutionInstanceReady(SolutionInstance solutionInstance)
at JetBrains.ProjectModel.SolutionManagerBase.CreateSolutionInstance(SolutionElement solutionElement, SolutionInstance solutionInstance)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHostManager.OpenSolution(ISolutionMark solutionMark, Object cookie)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHostManager.OpenSolution(FileSystemPath location, Object cookie)
at JetBrains.CommandLine.InspectCode.Unattended.Console.InspectCodeProductMain.<>c__DisplayClass4_0.<OpenSolution>b__0()
at JetBrains.Threading.ReentrancyGuard.Execute(String name, Action action)
at JetBrains.CommandLine.InspectCode.Unattended.Console.InspectCodeProductMain.OpenSolution(FileSystemPath solutionFilePath, IShellLocks shellLocks, ILogger logger, SolutionHostManager solutionHost)
at JetBrains.CommandLine.InspectCode.Unattended.Console.InspectCodeProductMain.Main(Lifetime lifetime, IThreading invocator, IComponentContainer container, IShellLocks shellLocks, ILogger logger, IInspectCodeSettings settings, IProductCommandLineArguments argumentsRaw, IProductInfo productInfo)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /_/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs:line 469
at JetBrains.Application.Environment.RunsPublicStaticIntMain.<>c__DisplayClass0_0.<.ctor>b__0()
at JetBrains.Application.Environment.RunsPublicStaticIntMain.<>c__DisplayClass0_2.<.ctor>b__5()
at JetBrains.Util.Logging.Logger.Catch(Action action)
at JetBrains.Application.Threading.IThreadingEx.<>c__DisplayClass18_1.<ExecuteOrQueueWhenNotGuarded>b__4()
at JetBrains.Threading.JetDispatcher.Closure.Execute()
at JetBrains.Threading.JetDispatcher.Run(Func`1 condition, TimeSpan timeout, Boolean bThrowOnTimeout)
at JetBrains.Application.Environment.IJetHostEx.RunHostMessageLoop(IComponentContainer containerEnv)
at JetBrains.Application.Environment.HostParameters.MessagePumpMainLoopHostMixin.JetBrains.Application.Environment.HostParameters.IRunMainLoopHostMixin.RunMainLoop(ComponentContainer containerEnv)
at JetBrains.Application.Environment.HostParameters.JetHostParametersCaller.RunMainLoop(ComponentContainer containerEnv)
at JetBrains.Application.Environment.JetEnvironment.InternalRun(JetHostParametersCaller host, ComponentContainer containerEnv)
at JetBrains.Application.Environment.JetEnvironment.CreateAndRun(Full hostparams)
at JetBrains.Application.Environment.JetHostItems.CreateAndRun(Full input)
at JetBrains.ReSharperAutomationTools.CommandLine.Common.Application.CommandLineProgram.Main(Assembly assembly, Type environmentZoneType, HostInfo hostInfo, String[] args, IJetHostMixin[] mixins)
at JetBrains.ReSharperAutomationTools.CommandLine.Common.Application.CommandLineProgram.Run[TZone](String productHostShortName, String[] args)
at JetBrains.CommandLine.InspectCode.InspectCodeProgram.Main(String[] args)

Value cannot be null. (Parameter 'input')

--- EXCEPTION #1/2 [ArgumentNullException]
Message = “Value cannot be null.”
ExceptionPath = Root.InnerException
ClassName = System.ArgumentNullException
Data.ThreadLocalDebugInfo = “Open solution”
HResult = E_POINTER=COR_E_NULLREFERENCE=80004003
Source = System.Text.RegularExpressions
ParamName = input
StackTraceString = “
at System.Text.RegularExpressions.Regex.Match(String input) in /_/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Match.cs:line 98
at System.Text.RegularExpressions.Regex.Match(String input, String pattern) in /_/src/System.Text.RegularExpressions/src/System/Text/RegularExpressions/Regex.Match.cs:line 69
at JetBrains.Platform.MsBuildHost.Process.MsBuildExternalProcess.GetProcessStartInfo(Int32 port)
at JetBrains.Platform.RdFramework.ExternalProcess.ProtocolExternalProcess`2.CreateProcess(IProtocol protocol, LifetimeDefinition processLifetimeDefinition, StartupOutputWriter outputWriter)
at JetBrains.Platform.RdFramework.ExternalProcess.ProtocolExternalProcess`2.Run()
at JetBrains.Platform.MsBuildHost.MsBuildConnectionFactory.Create(Lifetime lifetime, MsBuildConnectionContext context)
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildSessionHolder.CreateSession()
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildSessionHolder.TryExecute[T](Func`2 executor, T& result)
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildProjectHost.Reload(Lifetime lifetime, IReadOnlyCollection`1 changes, IReloadEventsConsumer reloadEventsConsumer, FileSystemPath logPath)

--- Outer ---

--- EXCEPTION #2/2 [LoggerException]
Message = “Value cannot be null. (Parameter 'input')”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
InnerException = “Exception #1 at Root.InnerException”
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
at JetBrains.Util.ILoggerEx.LogException(ILogger this, LoggingLevel level, Exception exception, ExceptionOrigin exceptionOrigin, String comment)
at JetBrains.Util.ILoggerEx.Error(ILogger this, Exception exception, ExceptionOrigin origin, String comment)
at JetBrains.ProjectModel.ProjectsHost.MsBuild.MsBuildProjectHost.Reload(Lifetime lifetime, IReadOnlyCollection`1 changes, IReloadEventsConsumer reloadEventsConsumer, FileSystemPath logPath)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.Load(ICollection`1 changesToAdd, ICollection`1 changesToUpdate, ICollection`1 changesToRemove, FileSystemPath logPath, ProjectStructureStamp stamp)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.<>c__DisplayClass32_0.<LoadAndSync>b__1()
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.ProjectHostReloadTaskExecutor.Execute(Func`1 executeAction, Action`1 notifyAction, Boolean async)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.BuildSolutionStructure(SolutionStructureChange solutionStructureChange)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.ReloadSolutionInternal(IForceUpdateProjectsPolicy forceUpdateProjectsPolicy)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.ReloadSolution()
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHost.Init()
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHostManager.SolutionInstanceReady(SolutionInstance solutionInstance)
at JetBrains.ProjectModel.SolutionManagerBase.CreateSolutionInstance(SolutionElement solutionElement, SolutionInstance solutionInstance)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHostManager.OpenSolution(ISolutionMark solutionMark, Object cookie)
at JetBrains.ProjectModel.ProjectsHost.SolutionHost.Impl.SolutionHostManager.OpenSolution(FileSystemPath location, Object cookie)
at JetBrains.CommandLine.InspectCode.Unattended.Console.InspectCodeProductMain.<>c__DisplayClass4_0.<OpenSolution>b__0()
at JetBrains.Threading.ReentrancyGuard.Execute(String name, Action action)
at JetBrains.CommandLine.InspectCode.Unattended.Console.InspectCodeProductMain.OpenSolution(FileSystemPath solutionFilePath, IShellLocks shellLocks, ILogger logger, SolutionHostManager solutionHost)
at JetBrains.CommandLine.InspectCode.Unattended.Console.InspectCodeProductMain.Main(Lifetime lifetime, IThreading invocator, IComponentContainer container, IShellLocks shellLocks, ILogger logger, IInspectCodeSettings settings, IProductCommandLineArguments argumentsRaw, IProductInfo productInfo)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /_/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs:line 469
at JetBrains.Application.Environment.RunsPublicStaticIntMain.<>c__DisplayClass0_0.<.ctor>b__0()
at JetBrains.Application.Environment.RunsPublicStaticIntMain.<>c__DisplayClass0_2.<.ctor>b__5()
at JetBrains.Util.Logging.Logger.Catch(Action action)
at JetBrains.Application.Threading.IThreadingEx.<>c__DisplayClass18_1.<ExecuteOrQueueWhenNotGuarded>b__4()
at JetBrains.Threading.JetDispatcher.Closure.Execute()
at JetBrains.Threading.JetDispatcher.Run(Func`1 condition, TimeSpan timeout, Boolean bThrowOnTimeout)
at JetBrains.Application.Environment.IJetHostEx.RunHostMessageLoop(IComponentContainer containerEnv)
at JetBrains.Application.Environment.HostParameters.MessagePumpMainLoopHostMixin.JetBrains.Application.Environment.HostParameters.IRunMainLoopHostMixin.RunMainLoop(ComponentContainer containerEnv)
at JetBrains.Application.Environment.HostParameters.JetHostParametersCaller.RunMainLoop(ComponentContainer containerEnv)
at JetBrains.Application.Environment.JetEnvironment.InternalRun(JetHostParametersCaller host, ComponentContainer containerEnv)
at JetBrains.Application.Environment.JetEnvironment.CreateAndRun(Full hostparams)
at JetBrains.Application.Environment.JetHostItems.CreateAndRun(Full input)
at JetBrains.ReSharperAutomationTools.CommandLine.Common.Application.CommandLineProgram.Main(Assembly assembly, Type environmentZoneType, HostInfo hostInfo, String[] args, IJetHostMixin[] mixins)
at JetBrains.ReSharperAutomationTools.CommandLine.Common.Application.CommandLineProgram.Run[TZone](String productHostShortName, String[] args)
at JetBrains.CommandLine.InspectCode.InspectCodeProgram.Main(String[] args)

Value cannot be null. (Parameter 'input')
No files to inspect were found.

(and the process hangs, I have to stop it with CTRL-C)

 

0
Comment actions Permalink
$ ./inspectcode.sh --mono=$(which mono) /home/hhyyrylainen/Projects/thrive/Thrive.sln

Into which path is $(which mono) being resolved? The path should point to actual msbuild dll which mono can execute. Something like: /Library/Frameworks/Mono.framework/Versions/6.10.0/lib/mono/msbuild/Current/bin/MSBuild.dll

--toolset-path parameter isn't necessary when --mono is used.

0
Comment actions Permalink

Thanks for the hint, I was able to find that

./inspectcode.sh --toolset-path=/usr/lib/mono/msbuild/Current/bin/MSBuild.dll

Works. However this doesn't work (fails with MSBuild not found):

./inspectcode.sh --mono=/usr/lib/mono/msbuild/Current/bin/MSBuild.dll

Now I'm unsure how I'm supposed to script this? Do I just write my script to assume that on Linux that is the msbuild path always? Or is there a way to get the path. It seems like your older cli tools had the Unix version that found that kind of thing automatically. And how would I do that on Windows (I'm already neglecting our Windows code checks running process pretty badly)?

0
Comment actions Permalink

I would suggest using "which mono" command in the bash script to retrieve the Mono installation path and adding the rest of the path to the MSBuild.dll

I believe it should work fine on Windows without specifying the --toolset-path

 

0
Comment actions Permalink

That's good to hear about the Windows version. The problem with "which mono" is that it returns:

/usr/bin/mono

But the msbuild DLL file is at:

/usr/lib/mono/msbuild/Current/bin/MSBuild.dll

which msbuild results in: /usr/bin/msbuild

so I can't see a way to get from one to the other.

I tried to look up if running mono with some flag could tell where it loads the msbuild dlls from but couldn't find anything. So I guess I just need to hardcode a default with the option to customize. Actually it seems like msbuild is a script file that contains the actual dll name in text so I could try to parse that.

0
Comment actions Permalink

Here's the script I ended up writing that extracts the actual dll location from the msbuild script: https://github.com/Revolutionary-Games/Thrive/blob/ce81d71d9baf8eddb1e14c2049d54201bdcdc887/check_formatting.rb#L61

0

Please sign in to leave a comment.