private static string GetProjectGuid(string fullname, IVsSolution5 vsSolution5) { ThreadHelper.ThrowIfNotOnUIThread(); var guid = vsSolution5.GetGuidOfProjectFile(fullname); return(guid.ToString()); }
private Guid GetProjectGuid() { var project = GetProject(); if (project == null) { return(Guid.Empty); } return(vsSolution.GetGuidOfProjectFile(project.FileName)); }
private Guid GetProjectGuid() { var project = GetProject(); if (project == null) { return(Guid.Empty); } try { return(vsSolution.GetGuidOfProjectFile(project.FileName)); } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { logger.LogDebug(Strings.TextBufferIssueTracker_ProjectGuidError, FilePath, ex); return(Guid.Empty); } }
private void BuildProjectPathToIdMap() { projectPathToProjectIdMap = new Dictionary <string, string>(StringComparer.InvariantCultureIgnoreCase); IVsSolution solution = this.serviceProvider.GetService <SVsSolution, IVsSolution>(); Debug.Assert(solution != null, "Cannot find SVsSolution"); // 1. Call with nulls to get the number of files const uint grfGetOpsIncludeUnloadedFiles = 0; // required since the projects might not have finished loading uint fileCount; var result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, 0, null, out fileCount); if (ErrorHandler.Failed(result)) { return; } // 2. Size array and call again to get the data string[] fileNames = new string[fileCount]; result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, fileCount, fileNames, out fileCount); if (ErrorHandler.Failed(result)) { return; } IVsSolution5 soln5 = (IVsSolution5)solution; foreach (string projectFile in fileNames) { // We need to use the same project id that is used by the Scanner for MSBuild. // For non-.Net Core projects, the scanner will use the <ProjectGuid> value in the project. // .Net Core projects don't have a <ProjectGuid> property so the scanner uses the GUID allocated // to the project in the solution file. // Fortunately, this is the logic used by soln5.GetGuidOfProjectFile... so we can just use that. Guid projectId = soln5.GetGuidOfProjectFile(projectFile); Debug.Assert(projectId != null, "Not expecting VS to return a null project guid"); projectPathToProjectIdMap.Add(projectFile, projectId.ToString().Replace("{", "").Replace("}", "")); } }
internal /* for testing */ static IDictionary <string, string> BuildProjectPathToIdMap(IVsSolution solution) { var map = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); // 1. Call with nulls to get the number of files const uint grfGetOpsIncludeUnloadedFiles = 0; // required since the projects might not have finished loading uint fileCount; var result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, 0, null, out fileCount); if (ErrorHandler.Failed(result)) { return(map); } // 2. Size array and call again to get the data string[] fileNames = new string[fileCount]; result = solution.GetProjectFilesInSolution(grfGetOpsIncludeUnloadedFiles, fileCount, fileNames, out _); if (ErrorHandler.Failed(result)) { return(map); } IVsSolution5 soln5 = (IVsSolution5)solution; foreach (string projectFile in fileNames) { // We need to use the same project id that is used by the Scanner for MSBuild. // For non-.Net Core projects, the scanner will use the <ProjectGuid> value in the project. // .Net Core projects don't have a <ProjectGuid> property so the scanner uses the GUID allocated // to the project in the solution file. // Fortunately, this is the logic used by soln5.GetGuidOfProjectFile... so we can just use that. Guid projectGuid = soln5.GetGuidOfProjectFile(projectFile); // Overwrite duplicate entries. This won't happen for real project files: it will only happen // for solution folders with duplicate names, which we don't care about. map[projectFile] = projectGuid.ToString().Replace("{", "").Replace("}", ""); } return(map); }
public Guid GetGuidOfProjectFile(string pszProjectFile) { return(_solution.GetGuidOfProjectFile(pszProjectFile)); }