public void Initalize(IConfiguration configuration) { _options = new MSBuildOptions(); ConfigurationBinder.Bind(configuration, _options); if (_environment.LogLevel < LogLevel.Information) { var buildEnvironmentInfo = MSBuildHelpers.GetBuildEnvironmentInfo(); _logger.LogDebug($"MSBuild environment: {Environment.NewLine}{buildEnvironmentInfo}"); } _packageDependencyChecker = new PackageDependencyChecker(_loggerFactory, _eventEmitter, _dotNetCli, _options); _loader = new ProjectLoader(_options, _environment.TargetDirectory, _propertyOverrides, _loggerFactory, _sdksPathResolver); _manager = new ProjectManager(_loggerFactory, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace); var initialProjectPaths = GetInitialProjectPaths(); foreach (var projectFilePath in initialProjectPaths) { if (!File.Exists(projectFilePath)) { _logger.LogWarning($"Found project that doesn't exist on disk: {projectFilePath}"); continue; } _manager.QueueProjectUpdate(projectFilePath, allowAutoRestore: true); } }
public static void Initialize(ILogger logger) { if (s_isInitialized) { throw new InvalidOperationException("MSBuild environment is already initialized."); } // If MSBuild can locate VS 2017 and set up a build environment, we don't need to do anything. // MSBuild will take care of itself. if (MSBuildHelpers.TryGetVisualStudioBuildEnvironment()) { logger.LogInformation("MSBuild will use local Visual Studio installation."); s_usingVisualStudio = true; s_isInitialized = true; } else if (TryWithLocalMSBuild(logger, out var msbuildExePath, out var msbuildExtensionsPath)) { logger.LogInformation("MSBuild will use local OmniSharp installation."); s_msbuildExePath = msbuildExePath; s_msbuildExtensionsPath = msbuildExtensionsPath; s_isInitialized = true; } if (!s_isInitialized) { logger.LogError("MSBuild environment could not be initialized."); } }
public void Initalize(IConfiguration configuration) { if (Initialized) { return; } _options = new MSBuildOptions(); ConfigurationBinder.Bind(configuration, _options); _sdksPathResolver.Enabled = _options.UseLegacySdkResolver; _sdksPathResolver.OverridePath = _options.MSBuildSDKsPath; if (_environment.LogLevel < LogLevel.Information) { var buildEnvironmentInfo = MSBuildHelpers.GetBuildEnvironmentInfo(); _logger.LogDebug($"MSBuild environment: {Environment.NewLine}{buildEnvironmentInfo}"); } _packageDependencyChecker = new PackageDependencyChecker(_loggerFactory, _eventEmitter, _dotNetCli, _options); _loader = new ProjectLoader(_options, _environment.TargetDirectory, _propertyOverrides, _loggerFactory, _sdksPathResolver); var dotNetInfo = GetDotNetInfo(); _manager = new ProjectManager(_loggerFactory, _options, _eventEmitter, _fileSystemWatcher, _metadataFileReferenceCache, _packageDependencyChecker, _loader, _workspace, _assemblyLoader, _eventSinks, dotNetInfo); Initialized = true; if (_options.LoadProjectsOnDemand) { _logger.LogInformation($"Skip loading projects listed in solution file or under target directory because {Key}:{nameof(MSBuildOptions.LoadProjectsOnDemand)} is true."); return; } var initialProjectPathsAndIds = GetInitialProjectPathsAndIds(); foreach (var(projectFilePath, projectIdInfo) in initialProjectPathsAndIds) { if (!File.Exists(projectFilePath)) { _logger.LogWarning($"Found project that doesn't exist on disk: {projectFilePath}"); continue; } _manager.QueueProjectUpdate(projectFilePath, allowAutoRestore: true, projectIdInfo); } }
public void Initalize(IConfiguration configuration) { _options = new MSBuildOptions(); ConfigurationBinder.Bind(configuration, _options); if (!MSBuildEnvironment.IsInitialized) { MSBuildEnvironment.Initialize(_logger); if (MSBuildEnvironment.IsInitialized && _environment.LogLevel < LogLevel.Information) { var buildEnvironmentInfo = MSBuildHelpers.GetBuildEnvironmentInfo(); _logger.LogDebug($"MSBuild environment: {Environment.NewLine}{buildEnvironmentInfo}"); } } var initialProjectPaths = GetInitialProjectPaths(); foreach (var projectPath in initialProjectPaths) { if (!File.Exists(projectPath)) { _logger.LogWarning($"Found project that doesn't exist on disk: {projectPath}"); continue; } var project = LoadProject(projectPath); if (project == null) { // Diagnostics reported while loading the project have already been logged. continue; } _projectsToProcess.Enqueue(project); } ProcessProjects(); }
public static void Initialize(ILogger logger) { if (s_isInitialized) { throw new InvalidOperationException("MSBuild environment is already initialized."); } // If MSBuild can locate VS 2017 and set up a build environment, we don't need to do anything. // MSBuild will take care of itself. if (MSBuildHelpers.CanInitializeVisualStudioBuildEnvironment()) { s_kind = MSBuildEnvironmentKind.VisualStudio; s_isInitialized = true; } else if (TryWithMonoMSBuild()) { s_kind = MSBuildEnvironmentKind.Mono; s_isInitialized = true; } else if (TryWithLocalMSBuild()) { s_kind = MSBuildEnvironmentKind.StandAlone; s_isInitialized = true; } else { s_kind = MSBuildEnvironmentKind.Unknown; logger.LogError("MSBuild environment could not be initialized."); s_isInitialized = false; } if (!s_isInitialized) { return; } var summary = new StringBuilder(); switch (s_kind) { case MSBuildEnvironmentKind.VisualStudio: summary.AppendLine("OmniSharp initialized with Visual Studio MSBuild."); break; case MSBuildEnvironmentKind.Mono: summary.AppendLine("OmniSharp initialized with Mono MSBuild."); break; case MSBuildEnvironmentKind.StandAlone: summary.AppendLine("Omnisharp will use local MSBuild."); break; } if (s_msbuildExePath != null) { summary.AppendLine($" MSBUILD_EXE_PATH: {s_msbuildExePath}"); } if (s_msbuildExtensionsPath != null) { summary.AppendLine($" MSBuildExtensionsPath: {s_msbuildExtensionsPath}"); } if (s_targetFrameworkRootPath != null) { summary.AppendLine($" TargetFrameworkRootPath: {s_targetFrameworkRootPath}"); } if (s_roslynTargetsPath != null) { summary.AppendLine($" RoslynTargetsPath: {s_roslynTargetsPath}"); } if (s_cscToolPath != null) { summary.AppendLine($" CscToolPath: {s_cscToolPath}"); } logger.LogInformation(summary.ToString()); }