public async Task RunTask() { Console.WriteLine(Environment.NewLine); Console.WriteLine(this.Name); Console.WriteLine(Environment.NewLine); Console.WriteLine("Input solution path."); Console.WriteLine(Environment.NewLine); string solutionPath = Console.ReadLine(); if (!File.Exists(solutionPath)) { Console.WriteLine("File does not exists!"); return; } using MSBuildWorkspace workspace = await new MSBuildWorkspaceFactory().GetWorkspace(); Solution solution = await workspace.OpenSolutionAsync(solutionPath); await foreach (CreateProjectGroup? result in TaskExecutable.RunTaskAsyncEnumerable(this.SelectProjectTask, solution)) { if (result == null || result.Project == null) { continue; } workspace.TryApplyChanges(result.Project.Solution); } workspace.CloseSolution(); }
private void UnloadWorkspace() { ProjectCollection.UnloadAllProjects(); _projectCache.Clear(); _workspace?.CloseSolution(); _workspace?.Dispose(); _workspace = null; }
public void CloseSolution() { if (m_solution != null) { m_workspace.CloseSolution(); m_solution = null; } }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { msbuildWorkspace.CloseSolution(); } disposedValue = true; } }
public Task CodeGen(TextWriter textWriter, bool addHeader = true) { MSBuildWorkspace workspace = MSBuildWorkspace.Create(); Project project = workspace.OpenProjectAsync(_csProjPath).Result; if (project == null) { throw new ArgumentException("Could not open the project located at " + _csProjPath); } StringWriter classes = new StringWriter(); var usings = new HashSet <string>(); foreach (ICodeGenParticipant codeGenParticipant in _codeGenParticipants) { CodeGenResult result = codeGenParticipant.CodeGen(workspace, project).Result; classes.Write(result.Code); usings.UnionWith(result.Usings); if (codeGenParticipant != _codeGenParticipants.Last()) { classes.Write(Environment.NewLine); classes.Write(Environment.NewLine); } } if (addHeader) { AddHeader(textWriter); textWriter.Write(Environment.NewLine); } foreach (string nameSpace in usings) { textWriter.Write("using {0};", nameSpace); textWriter.Write(Environment.NewLine); } textWriter.Write(Environment.NewLine); textWriter.Write(classes); workspace.CloseSolution(); return(Task.FromResult(false)); }
public async Task RunTask() { Console.WriteLine(Environment.NewLine); Console.WriteLine(this.Name); Console.WriteLine(Environment.NewLine); TagTemplateGroup?template = await TaskExecutable.RunTask(this.LoadTemplate); if (template == null) { return; } Console.WriteLine("Input solution path."); Console.WriteLine(Environment.NewLine); string solutionPath = Console.ReadLine(); if (!File.Exists(solutionPath)) { Console.WriteLine("File does not exists!"); return; } using MSBuildWorkspace workspace = await new MSBuildWorkspaceFactory().GetWorkspace(); Solution solution = await workspace.OpenSolutionAsync(solutionPath); Console.WriteLine(Environment.NewLine); Console.WriteLine("Select project:"); Project?project = await TaskExecutable.RunTask(CommonTaskFunctions.GetProjectTask, solution); if (project == null) { return; } var selectedDocuments = new List <Document>(); await foreach (Document? document in TaskExecutable.RunTaskAsyncEnumerable(CommonTaskFunctions.SelectDocuments, project.Documents.Where(whereDocument => !selectedDocuments.Contains(whereDocument)))) { if (document != null) { selectedDocuments.Add(document); } } TagProjectGroup projectGroup = await CommonTaskFunctions.ImplementsTags(selectedDocuments, template.TagElements); List <Document> documents = new List <Document>(); foreach (DocumentGroup createDocument in template.Documents) { foreach (TagDocumentGroup documentGroup in projectGroup.Documents) { TagDocumentGroup newDocumentGroup = CommonTaskFunctions.ReplaceDocumentTags(documentGroup, createDocument.ReplacedTags); Document? newDocument = CommonTaskFunctions.AppendDocumentToProject(project, newDocumentGroup); if (newDocument != null) { project = newDocument.Project; documents.Add(newDocument); } } } workspace.TryApplyChanges(project.Solution); workspace.CloseSolution(); }