private static Option<bool> GetFullSolutionAnalysisOption(IServiceProvider serviceProvider)
{
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
string codeAnalysisDllPath = typeof(Accessibility).Assembly.Location;
if (string.IsNullOrEmpty(codeAnalysisDllPath))
{
Debug.Fail("Microsoft.CodeAnalysis.dll could not be located");
return null;
}
FileInfo codeAnalysisAssembly = new FileInfo(codeAnalysisDllPath);
if (!codeAnalysisAssembly.Exists)
{
Debug.Fail("Microsoft.CodeAnalysis.dll could not be located");
return null;
}
string codeAnalysisFolderPath = codeAnalysisAssembly.Directory.FullName;
const string codeAnalysisFeaturesDllName = "Microsoft.CodeAnalysis.Features.dll";
// There's no public type in the DLL, so we try finding it next to Microsoft.CodeAnalysis
string path = Path.Combine(codeAnalysisFolderPath, codeAnalysisFeaturesDllName);
if (!File.Exists(path))
{
VsShellUtils.WriteToSonarLintOutputPane(serviceProvider, Strings.MissingResourceAtLocation,
codeAnalysisFeaturesDllName, codeAnalysisFolderPath);
return null;
}
// This is only part of Visual Studio 2015 Update 2
Option<bool> option = (Option<bool>)Assembly.LoadFile(path)
.GetType("Microsoft.CodeAnalysis.Shared.Options.RuntimeOptions", false)
?.GetField("FullSolutionAnalysis")
?.GetValue(null);
Debug.Assert(option != null, "RuntimeOptions is not found");
Debug.Assert(option.Name == OptionNameFullSolutionAnalysis, OptionNameFullSolutionAnalysis + " option name changed to " + option.Name);
Debug.Assert(option.Feature == OptionFeatureRuntime, OptionFeatureRuntime + " option feature changed to " + option.Feature);
return option;
}