protected Dictionary <string, DetectedReference> GetReferences(Microsoft.CodeAnalysis.Project parentProject) { var dict = new Dictionary <string, DetectedReference>(); foreach (var reference in parentProject.MetadataReferences) { using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) { string assemblyName = assemblyDef.Name.Name; if (IsReferenceAssembly(assemblyDef)) { string resolvedAssemblyFile = GacInterop.FindAssemblyInNetGac(assemblyDef.Name); dict.Add(assemblyName, new DetectedReference(assemblyName, resolvedAssemblyFile, false)); } else { dict.Add(assemblyName, new DetectedReference(assemblyName, reference.Display, false)); } } } foreach (var projectReference in parentProject.ProjectReferences) { var roslynProject = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId); var project = FindProject(owner.DTE.Solution.Projects.OfType <EnvDTE.Project>(), roslynProject.FilePath); if (roslynProject != null && project != null) { dict.Add(roslynProject.AssemblyName, new DetectedReference(roslynProject.AssemblyName, Utils.GetProjectOutputAssembly(project, roslynProject), true)); } } return(dict); }
protected Dictionary <string, string> GetReferences(Microsoft.CodeAnalysis.Project parentProject) { var dict = new Dictionary <string, string>(); foreach (var reference in parentProject.MetadataReferences) { using (var assemblyDef = AssemblyDefinition.ReadAssembly(reference.Display)) { if (IsReferenceAssembly(assemblyDef)) { dict.Add(assemblyDef.Name.Name, GacInterop.FindAssemblyInNetGac(assemblyDef.Name)); } else { dict.Add(assemblyDef.Name.Name, reference.Display); } } } foreach (var projectReference in parentProject.ProjectReferences) { var roslynProject = owner.Workspace.CurrentSolution.GetProject(projectReference.ProjectId); var project = owner.DTE.Solution.Projects.OfType <EnvDTE.Project>().FirstOrDefault(p => p.FileName == roslynProject.FilePath); if (roslynProject != null && project != null) { dict.Add(roslynProject.AssemblyName, GetProjectOutputPath(project, roslynProject)); } } return(dict); }
static StringBuilder Display(Microsoft.CodeAnalysis.Project project) { StringBuilder sb = new StringBuilder(); // Print the root of the solution sb.AppendLine(Path.GetFileName(project.FilePath)); sb.AppendLine("> " + project.Name); sb.AppendLine(" > MetadataReferences"); foreach (var reference in project.MetadataReferences) { sb.AppendLine(" - " + reference.Display); } //sb.AppendLine(" > ProjectReferences"); Microsoft.CodeAnalysis.Solution solution = project.Solution; foreach (var reference in project.ProjectReferences) { sb.AppendLine(" - " + solution.GetProject(reference.ProjectId).Name); } sb.AppendLine(" > Documents"); foreach (var document in project.Documents) { sb.AppendLine(" - " + document.Name + " " + document.GetType().ToString()); } return(sb); }
protected async Task <Microsoft.CodeAnalysis.Emit.EmitResult> EmitProject(Microsoft.CodeAnalysis.Project project) { var compilation = await project.GetCompilationAsync(); string pdbPath = SysIO.Path.Combine(SysIO.Path.GetDirectoryName(project.OutputFilePath), SysIO.Path.GetFileNameWithoutExtension(project.OutputFilePath) + ".pdb"); using (var fileStream = SysIO.File.Create(project.OutputFilePath)) using (var pdbStream = SysIO.File.Create(pdbPath)) return(compilation.Emit(fileStream, pdbStream)); }
private void _buildEvents_OnBuildProjConfigDone(string project, string projectConfig, string platform, string solutionConfig, bool success) { Project proj = _workspace.CurrentSolution.Projects .Single(prj => prj.Language == "C#" && new FileInfo(prj.FilePath).Name == project.Split('\\').Last()); if (proj != null) { _isBeingBuiltProjects.Add(proj); } }
private static void SetupReadonlyProjectAndSolution() { if (_readOnlyProject != null) { return; } _readOnlyProject = OpenProject(); _readOnlySolution = OpenSolution(); }
protected string GetProjectOutputPath(EnvDTE.Project project, Microsoft.CodeAnalysis.Project roslynProject) { string outputFileName = Path.GetFileName(roslynProject.OutputFilePath); //get the directory path based on the project file. string projectPath = Path.GetDirectoryName(project.FullName); //get the output path based on the active configuration string projectOutputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString(); //combine the project path and output path to get the bin path return(Path.Combine(projectPath, projectOutputPath, outputFileName)); }
public void DirectRoselyn() { string projectPath = Path.GetFullPath(@"..\..\..\Examples\SimpleLogger\LoggingTemplate.Mte\LoggingTemplate.Mte.csproj"); var workspace = MSBuildWorkspace.Create(); Project project = workspace.OpenProjectAsync(projectPath).Result; //var sut = new TestableFileTemplate(); //sut.Execute(new Config(null, projectPath)); }
private string MapTargetFramework(Microsoft.CodeAnalysis.Project proj) { var mscorlibVersion = new Regex(@"v([\d\.]+)\\.*?mscorlib\.dll$"); var frameworkVersion = proj.MetadataReferences.Select(m => mscorlibVersion.Match(m.Display)).FirstOrDefault(m => m.Success)?.Groups[1].Value; if (frameworkVersion != null) { return($".NET Framework {frameworkVersion}"); } _logger.Warning($"Target framework of the following project couldn't be determined: {proj.FilePath}"); return(null); }
public Project Map(Microsoft.CodeAnalysis.Project proj) { var compilation = proj.GetCompilationAsync().GetAwaiter().GetResult(); var sourceFiles = compilation.SyntaxTrees .Where(t => Path.GetExtension(t.FilePath) == ".cs") .Where(NotExcluded); return(new Project { FullName = proj.FilePath, Language = proj.Language, TargetFramework = MapTargetFramework(proj), Children = sourceFiles.Select(file => _lifetimeScope.Resolve <SourceFileVisitor>().Discover(file, compilation)).ToList() }); }
public static MonoDevelop.Projects.Project GetMonoProject(Microsoft.CodeAnalysis.Project project) { if (project == null) { throw new ArgumentNullException(nameof(project)); } foreach (var w in workspaces) { var documentId = w.GetMonoProject(project); if (documentId != null) { return(documentId); } } return(null); }
public static void Rename(ILogger _logger, string solutionPath, string projectPath, List <PreRenameData> lstRenames, CancellationToken cancellationToken) { using (Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create()) { // Open the solution within the workspace. Microsoft.CodeAnalysis.Solution solution = workspace.OpenSolutionAsync(solutionPath).Result; bool isProjectFound = false; foreach (Microsoft.CodeAnalysis.ProjectId projectId in solution.ProjectIds) { // Look up the snapshot for the original project in the latest forked solution. Microsoft.CodeAnalysis.Project project = solution.GetProject(projectId); if (project.FilePath == projectPath) { isProjectFound = true; foreach (Microsoft.CodeAnalysis.DocumentId documentId in project.DocumentIds) { // Look up the snapshot for the original document in the latest forked solution. Microsoft.CodeAnalysis.Document document = solution.GetDocument(documentId); //tg.RelativePathToGeneratedFile // only in 'main' declaration files //TODO implement based on knowledge of generated file ??? if (Path.GetDirectoryName(document.FilePath).EndsWith("ViewModels")) { if (Path.GetExtension(document.FilePath) == "cs") { CodeAnalysisCSharp.Rename(_logger, solution, document, lstRenames, cancellationToken).Wait(); } else if (Path.GetExtension(document.FilePath) == "vb") { CodeAnalysisVisualBasic.Rename(solution, document, lstRenames, cancellationToken).Wait(); } else { throw new NotSupportedException(); } } } } } if (!isProjectFound) { throw new Exception("Project not found"); } } }
public static string GetProjectOutputAssembly(Project project, Microsoft.CodeAnalysis.Project roslynProject) { string outputFileName = Path.GetFileName(roslynProject.OutputFilePath); // Get the directory path based on the project file. string projectPath = Path.GetDirectoryName(project.FullName); // Get the output path based on the active configuration string projectOutputPath = project.ConfigurationManager.ActiveConfiguration.Properties.Item("OutputPath").Value.ToString(); // Combine the project path and output path to get the bin path if ((projectPath != null) && (projectOutputPath != null) && (outputFileName != null)) { return(Path.Combine(projectPath, projectOutputPath, outputFileName)); } return(null); }
static List <CGFDocument> ProcessDocuments(CGFParserReporter reporter, List <Microsoft.CodeAnalysis.Document> documents, Microsoft.CodeAnalysis.Project project) { using (reporter.CreateContextScope(CGFParserReporterContext.Type.Project, project.FilePath)) { List <CGFDocument> documentsToProcess = new List <CGFDocument>(); foreach (Microsoft.CodeAnalysis.Document document in documents) { using (reporter.CreateContextScope(CGFParserReporterContext.Type.File, document.FilePath)) { List <CGFTypeSymbol> typesToProcess = new List <CGFTypeSymbol>(); Microsoft.CodeAnalysis.SemanticModel semanticModel = document.GetSemanticModelAsync().Result; Microsoft.CodeAnalysis.SyntaxTree syntaxTree = document.GetSyntaxTreeAsync().Result; IEnumerable <Microsoft.CodeAnalysis.SyntaxNode> syntaxNodes = syntaxTree.GetRoot().DescendantNodes().Where(n => (n as ClassDeclarationSyntax) != null || (n as EnumDeclarationSyntax) != null); foreach (Microsoft.CodeAnalysis.SyntaxNode node in syntaxNodes) { ClassDeclarationSyntax classSyntax = node as ClassDeclarationSyntax; if (classSyntax != null) { Microsoft.CodeAnalysis.INamedTypeSymbol typeSymbol = semanticModel.GetDeclaredSymbol(classSyntax); using (reporter.CreateContextScope(CGFParserReporterContext.Type.Type, typeSymbol.Name)) { CGFTypeSymbol cgfTypeSymbol = CGFTypeSymbol.Parse(reporter, typeSymbol); typesToProcess.Add(cgfTypeSymbol); } } else { EnumDeclarationSyntax enumSyntax = node as EnumDeclarationSyntax; Microsoft.CodeAnalysis.INamedTypeSymbol typeSymbol = semanticModel.GetDeclaredSymbol(enumSyntax); using (reporter.CreateContextScope(CGFParserReporterContext.Type.Type, typeSymbol.Name)) { CGFTypeSymbol cgfTypeSymbol = CGFTypeSymbol.Parse(reporter, typeSymbol); typesToProcess.Add(cgfTypeSymbol); } } } if (typesToProcess.Count > 0) { CGFDocument cgfDocument = CGFDocument.Parse(reporter, document, typesToProcess); documentsToProcess.Add(cgfDocument); } } } return(documentsToProcess); } }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { SelectProject dialog = new SelectProject(); DialogResult result = dialog.ShowDialog(); if (result == DialogResult.OK) { errorProvider.Tasks.Clear(); Task infoTask = new Task { Category = TaskCategory.User, Text = "Mutation testing has started. Mutants that your tests could not detect will appear here.", CanDelete = true, Priority = TaskPriority.Low }; errorProvider.Tasks.Add(infoTask); errorProvider.Show(); Project project = dialog.SelectedProject; Project testProject = dialog.SelectedTestProject; JoinableTaskFactory uiThread = new JoinableTaskFactory(new JoinableTaskContext()); IVsStatusbar statusBar = (IVsStatusbar)ServiceProvider.GetService(typeof(SVsStatusbar)); new System.Threading.Thread(() => { int killCount = 0; menuItem.Enabled = false; object icon = (short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Build; statusBar.SetText("Instrumenting code for mutation..."); statusBar.Animation(1, ref icon); try { CoveredProject coveredProject = new CoveredProject(project, testProject, (m) => { ++killCount; uiThread.Run(async() => UpdateProgress(m, statusBar, killCount)); //ListMutantInErrorWindow(m, true); }, (m) => { uiThread.Run(async() => { UpdateProgress(m, statusBar, killCount); ListMutantInErrorWindow(m, false); }); }); Result = coveredProject.MutateAndTestProject(); //Result.LiveMutants.ForEach(ListMutantInErrorWindow); Result.KilledMutants.ForEach((m) => uiThread.Run(async() => ListMutantInErrorWindow(m, true))); uiThread.Run(async() => statusBar.Animation(0, ref icon)); uiThread.Run(async() => statusBar.SetText("Mutation complete (" + killCount + " mutants killed)")); VsShellUtilities.ShowMessageBox(this.ServiceProvider, "Mutation complete. " + Result.LiveMutants.Count + " mutants lived. " + Result.KilledMutants.Count + " mutants successfully killed. See Error List pane for descriptions of live mutants.", "Mutation testing", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); } catch (Exception e2) { Task newError = new Task { Category = TaskCategory.User, Text = "Fatal error during mutation: " + e2.ToString(), CanDelete = true, Priority = TaskPriority.High }; errorProvider.Tasks.Add(newError); } finally { menuItem.Enabled = true; errorProvider.Tasks.Remove(infoTask); } }).Start(); } dialog.Dispose(); }
public ReadOnlyProjectAndSolution(Microsoft.CodeAnalysis.Project project, Microsoft.CodeAnalysis.Solution solution) { Project = project; Solution = solution; }
public ProjectUpdater(RoslynProject project) { m_project = project; }
ProjectItemForILSpy(Project project, Microsoft.CodeAnalysis.Project roslynProject, SelectedItem item) { this.project = project; this.roslynProject = roslynProject; this.item = item; }