public static async Task WriteToProjectAsync(string fileNamespace, string fileClass, Project prj, MSBuildWorkspace workspace) { await Task.Run(() => { if (workspace.CanApplyChange(ApplyChangesKind.AddDocument)) { string evaluated = Path.Combine(fileNamespace, string.Concat(fileClass, ".", Languages.cs.ToString())); Evaluation.Project projectEditor; if (!new Evaluation.Project().ProjectCollection.LoadedProjects.Where(p => p.FullPath.Equals(prj.FilePath)).Any()) { projectEditor = new Evaluation.Project(prj.FilePath); } else { projectEditor = new Evaluation.Project().ProjectCollection.LoadedProjects.Where(p => p.FullPath.Equals(prj.FilePath)).FirstOrDefault(); } // Creo il folder if (!projectEditor.GetItems(ProjectItemToInclude.Folder.ToString()).Where(p => p.EvaluatedInclude.Equals(fileNamespace)).Any()) { projectEditor.AddItem(ProjectItemToInclude.Folder.ToString(), fileNamespace); } // Creo il file if (!projectEditor.GetItemsByEvaluatedInclude(evaluated).Any()) { projectEditor.AddItem(ProjectItemToInclude.Compile.ToString(), evaluated); } projectEditor.Save(); } }); }
public static void LogSupportedChanges(MSBuildWorkspace workspace) { Log.Debug("Supported changes in the workspace:"); foreach (var changeKind in Enum.GetNames(typeof(ApplyChangesKind))) { var canChangeKind = workspace.CanApplyChange( (ApplyChangesKind)Enum.Parse( typeof(ApplyChangesKind), changeKind)); Log.Debug($"\t{changeKind}: {canChangeKind}"); } Log.Debug($"\t{nameof(workspace.CanOpenDocuments)}: {workspace.CanOpenDocuments}"); }
private static void LogSupportedChanges(MSBuildWorkspace workspace) { Program.Log.Info("Supported changes in the workspace:"); foreach (var changeKind in Enum.GetNames(typeof(ApplyChangesKind))) { var canChangeKind = workspace.CanApplyChange( (ApplyChangesKind)Enum.Parse( typeof(ApplyChangesKind), changeKind)); Program.Log.Info($"\t{changeKind}: {canChangeKind}"); } Program.Log.Info($"\t{nameof(workspace.CanOpenDocuments)}: {workspace.CanOpenDocuments}"); }