public void Initalize(IConfiguration configuration) { _options = new MSBuildOptions(); ConfigurationBinder.Bind(configuration, _options); if (_options.WaitForDebugger) { Console.WriteLine($"Attach to process {System.Diagnostics.Process.GetCurrentProcess().Id}"); while (!System.Diagnostics.Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } } var solutionFilePath = _env.SolutionFilePath; if (string.IsNullOrEmpty(solutionFilePath)) { var solutions = Directory.GetFiles(_env.Path, "*.sln"); var result = SolutionPicker.ChooseSolution(_env.Path, solutions); if (result.Message != null) { _logger.LogInformation(result.Message); } if (result.Solution == null) { return; } solutionFilePath = result.Solution; } SolutionFile solutionFile = null; _context.SolutionPath = solutionFilePath; using (var stream = File.OpenRead(solutionFilePath)) { using (var reader = new StreamReader(stream)) { solutionFile = SolutionFile.Parse(reader); } } _logger.LogInformation($"Detecting projects in '{solutionFilePath}'."); foreach (var block in solutionFile.ProjectBlocks) { if (!_supportsProjectTypes.Contains(block.ProjectTypeGuid)) { if (UnityTypeGuid(block.ProjectName) != block.ProjectTypeGuid) { _logger.LogWarning("Skipped unsupported project type '{0}'", block.ProjectPath); continue; } } if (_context.ProjectGuidToWorkspaceMapping.ContainsKey(block.ProjectGuid)) { continue; } var projectFilePath = Path.GetFullPath(Path.GetFullPath(Path.Combine(_env.Path, block.ProjectPath.Replace('\\', Path.DirectorySeparatorChar)))); _logger.LogInformation($"Loading project from '{projectFilePath}'."); var projectFileInfo = CreateProject(projectFilePath); if (projectFileInfo == null) { continue; } var compilationOptions = new CSharpCompilationOptions(projectFileInfo.OutputKind); compilationOptions = compilationOptions.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default); if (projectFileInfo.AllowUnsafe) { compilationOptions = compilationOptions.WithAllowUnsafe(true); } if (projectFileInfo.SignAssembly && !string.IsNullOrEmpty(projectFileInfo.AssemblyOriginatorKeyFile)) { var keyFile = Path.Combine(projectFileInfo.ProjectDirectory, projectFileInfo.AssemblyOriginatorKeyFile); compilationOptions = compilationOptions.WithStrongNameProvider(new DesktopStrongNameProvider()) .WithCryptoKeyFile(keyFile); } if (projectFileInfo.GenerateXmlDocumentation) { compilationOptions = compilationOptions.WithXmlReferenceResolver(XmlFileResolver.Default); } var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(projectFileInfo.Name), VersionStamp.Create(), projectFileInfo.Name, projectFileInfo.AssemblyName, LanguageNames.CSharp, projectFileInfo.ProjectFilePath, compilationOptions: compilationOptions); _workspace.AddProject(projectInfo); projectFileInfo.WorkspaceId = projectInfo.Id; _context.Projects[projectFileInfo.ProjectFilePath] = projectFileInfo; _context.ProjectGuidToWorkspaceMapping[block.ProjectGuid] = projectInfo.Id; _watcher.Watch(projectFilePath, OnProjectChanged); } foreach (var projectFileInfo in _context.Projects.Values) { UpdateProject(projectFileInfo); } }
public void Initalize(IConfiguration configuration) { _options = new MSBuildOptions(); OptionsServices.ReadProperties(_options, configuration); var solutionFilePath = _env.SolutionFilePath; if (string.IsNullOrEmpty(solutionFilePath)) { var solutions = Directory.GetFiles(_env.Path, "*.sln"); var result = SolutionPicker.ChooseSolution(_env.Path, solutions); if (result.Message != null) { _logger.LogInformation(result.Message); } if (result.Solution == null) { return; } solutionFilePath = result.Solution; } SolutionFile solutionFile = null; _context.SolutionPath = solutionFilePath; using (var stream = File.OpenRead(solutionFilePath)) { using (var reader = new StreamReader(stream)) { solutionFile = SolutionFile.Parse(reader); } } _logger.LogInformation($"Detecting projects in '{solutionFilePath}'."); foreach (var block in solutionFile.ProjectBlocks) { if (!_supportsProjectTypes.Contains(block.ProjectTypeGuid)) { if (UnityTypeGuid(block.ProjectName) != block.ProjectTypeGuid) { _logger.LogWarning("Skipped unsupported project type '{0}'", block.ProjectPath); continue; } } if (_context.ProjectGuidToWorkspaceMapping.ContainsKey(block.ProjectGuid)) { continue; } var projectFilePath = Path.GetFullPath(Path.GetFullPath(Path.Combine(_env.Path, block.ProjectPath.Replace('\\', Path.DirectorySeparatorChar)))); _logger.LogInformation($"Loading project from '{projectFilePath}'."); var projectFileInfo = CreateProject(projectFilePath); if (projectFileInfo == null) { continue; } var compilationOptions = new CSharpCompilationOptions(projectFileInfo.OutputKind); #if DNX451 compilationOptions = compilationOptions.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default); #endif if (projectFileInfo.AllowUnsafe) { compilationOptions = compilationOptions.WithAllowUnsafe(true); } var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(projectFileInfo.Name), VersionStamp.Create(), projectFileInfo.Name, projectFileInfo.AssemblyName, LanguageNames.CSharp, projectFileInfo.ProjectFilePath, compilationOptions: compilationOptions); _workspace.AddProject(projectInfo); projectFileInfo.WorkspaceId = projectInfo.Id; _context.Projects[projectFileInfo.ProjectFilePath] = projectFileInfo; _context.ProjectGuidToWorkspaceMapping[block.ProjectGuid] = projectInfo.Id; _watcher.Watch(projectFilePath, OnProjectChanged); } foreach (var projectFileInfo in _context.Projects.Values) { UpdateProject(projectFileInfo); } }
public void Initalize() { var solutionFilePath = _env.SolutionFilePath; if (string.IsNullOrEmpty(solutionFilePath)) { var solutions = Directory.GetFiles(_env.Path, "*.sln"); var result = SolutionPicker.ChooseSolution(_env.Path, solutions); if (result.Message != null) { _logger.WriteInformation(result.Message); } if (result.Solution == null) { return; } solutionFilePath = result.Solution; } SolutionFile solutionFile = null; _context.SolutionPath = solutionFilePath; using (var stream = File.OpenRead(solutionFilePath)) { using (var reader = new StreamReader(stream)) { solutionFile = SolutionFile.Parse(reader); } } _logger.WriteInformation(string.Format("Detecting projects in '{0}'.", solutionFilePath)); foreach (var block in solutionFile.ProjectBlocks) { if (!_supportsProjectTypes.Contains(block.ProjectTypeGuid)) { if (UnityTypeGuid(block.ProjectName) != block.ProjectTypeGuid) { _logger.WriteWarning("Skipped unsupported project type '{0}'", block.ProjectPath); continue; } } if (_context.ProjectGuidToWorkspaceMapping.ContainsKey(block.ProjectGuid)) { continue; } var projectFilePath = Path.GetFullPath(Path.GetFullPath(Path.Combine(_env.Path, block.ProjectPath.Replace('\\', Path.DirectorySeparatorChar)))); _logger.WriteInformation(string.Format("Loading project from '{0}'.", projectFilePath)); var projectFileInfo = CreateProject(projectFilePath); if (projectFileInfo == null) { continue; } var projectInfo = ProjectInfo.Create(ProjectId.CreateNewId(projectFileInfo.Name), VersionStamp.Create(), projectFileInfo.Name, projectFileInfo.AssemblyName, LanguageNames.CSharp, projectFileInfo.ProjectFilePath); _workspace.AddProject(projectInfo); projectFileInfo.WorkspaceId = projectInfo.Id; _context.Projects[projectFileInfo.ProjectFilePath] = projectFileInfo; _context.ProjectGuidToWorkspaceMapping[block.ProjectGuid] = projectInfo.Id; _watcher.Watch(projectFilePath, OnProjectChanged); } foreach (var projectFileInfo in _context.Projects.Values) { UpdateProject(projectFileInfo); } }