private string GetPrjTypeName(System.Guid priGuid) { System.Collections.Generic.IList <ProjectKind> projectKinds = ProjectKind.GetProjectKinds(priGuid); if (projectKinds != null && projectKinds.Count > 0) { return(TypeList.GetTypeName(projectKinds[0].PrjKind, "1", "ProjectType")); } return(string.Empty); }
private static void AddCompileItemsToProjectFile(string projFile, ProjectKind kind, CheckData check) { XDocument xmlFile = XDocument.Load(projFile); Debug.Assert(xmlFile.Root.Name.LocalName == "Project"); var first = xmlFile.Root.Descendants().Where(c => c.Name.LocalName == "Compile").First(); var parent = first.Parent; XElement elem = null; switch (kind) { case ProjectKind.Core: elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateAnalyzerFileName(check)); parent.Add(elem); elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateCodeFixFileName(check)); parent.Add(elem); break; case ProjectKind.CSharp: elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateCSharpAnalyzerFileName(check)); parent.Add(elem); elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateCSharpCodeFixFileName(check)); parent.Add(elem); break; case ProjectKind.VisualBasic: elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateBasicAnalyzerFileName(check)); parent.Add(elem); elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateBasicCodeFixFileName(check)); parent.Add(elem); break; case ProjectKind.UnitTests: elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateAnalyzerTestsFileName(check)); parent.Add(elem); elem = new XElement(first); elem.SetAttributeValue("Include", CodeTemplates.GenerateCodeFixTestsFileName(check)); parent.Add(elem); break; default: throw new ArgumentException(kind.ToString()); } xmlFile.Save(projFile); return; }
public static ProjectInformation CreateProjectInformation(this DotNetProject project) { return(new ProjectInformation { Name = project.Name, FileName = project.FileName, UniqueName = GetUniqueName(project), Kind = ProjectKind.GetProjectKind(project), TargetFrameworkMoniker = project.TargetFramework.Id.ToString(), Type = ProjectType.GetProjectType(project) }); }
public ProjectModel(string name, string fullPath, string projectIdentifier, ProjectKind kind, string projectKindId, string rootNamespace) { Name = name; FullPath = fullPath; Kind = kind; KindId = projectKindId; ProjectIdentifier = projectIdentifier; RootNamespace = rootNamespace; Children = new List <ProjectModel>(); TypeDescription = VsUtilities.GetProjectTypeDescription(projectKindId); }
public static void BuildProject( string outputDirectory, string sourceDirectory, string analyzer, ProjectKind kind, IEnumerable <string> copyFiles, IEnumerable <string> renamedFiles, string projectName, Dictionary <string, IEnumerable <string> > categories, Dictionary <string, Dictionary <string, string> > projectGuids, IList <CheckData> checks) { string target = Path.Combine(outputDirectory, "src", analyzer + ".Analyzers", kind.ToString()); Directory.CreateDirectory(target); // Identically named supporting Files string source = Path.Combine(sourceDirectory, "src", "REPLACE.ME", kind.ToString()); foreach (string copiedFile in copyFiles) { Utilities.CopyFile(source, target, copiedFile); } // Everybody gets an assemblyInfo, except vb and nuget if (kind != ProjectKind.VisualBasic && kind != ProjectKind.NuGet) { Directory.CreateDirectory(Path.Combine(target, "Properties")); Utilities.CopyFile(source, target, @"Properties\AssemblyInfo.cs"); } foreach (string renamedFile in renamedFiles) { if (renamedFile == "REPLACEMEAnalyzersResources.resx") { Debug.Assert(kind == ProjectKind.Core); Debug.Assert(checks != null); } Utilities.CopyRenamedFile(source, target, renamedFile, analyzer, checks, categories, projectGuids); } Dictionary <string, string> analyzerGuids; if (!projectGuids.TryGetValue(kind.ToString(), out analyzerGuids)) { projectGuids[kind.ToString()] = analyzerGuids = new Dictionary <string, string>(); } analyzerGuids[analyzer] = Utilities.CopyRenamedFile(source, target, projectName, analyzer, checks, categories, projectGuids); Utilities.CreateStubFiles(kind, target, analyzer, checks, categories); }
public static void CreateStubFiles(ProjectKind kind, string target, string analyzer, IList <CheckData> checks, Dictionary <string, IEnumerable <string> > categories) { if (kind == ProjectKind.Setup || kind == ProjectKind.NuGet) { return; } foreach (var check in checks) { if (kind == ProjectKind.Core) { Utilities.CreateFile(CodeTemplates.GenerateAnalyzer(analyzer, check), target, CodeTemplates.GenerateAnalyzerFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCodeFix(analyzer, check), target, CodeTemplates.GenerateCodeFixFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCategory(analyzer, categories[analyzer]), target, CodeTemplates.CategoryFileName); } else if (kind == ProjectKind.CSharp) { Utilities.CreateFile(CodeTemplates.GenerateCSharpAnalyzer(analyzer, check), target, CodeTemplates.GenerateCSharpAnalyzerFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCSharpCodeFix(analyzer, check), target, CodeTemplates.GenerateCSharpCodeFixFileName(check)); } else if (kind == ProjectKind.VisualBasic) { Utilities.CreateFile(CodeTemplates.GenerateBasicAnalyzer(analyzer, check), target, CodeTemplates.GenerateBasicAnalyzerFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateBasicCodeFix(analyzer, check), target, CodeTemplates.GenerateBasicCodeFixFileName(check)); } else if (kind == ProjectKind.UnitTests) { Utilities.CreateFile(CodeTemplates.GenerateAnalyzerTests(analyzer, check), target, CodeTemplates.GenerateAnalyzerTestsFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCodeFixTests(analyzer, check), target, CodeTemplates.GenerateCodeFixTestsFileName(check)); } } }
public IEnumerable <Project> GetAllProjects() { var projectList = new List <Project>(); var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE)); foreach (Project project in dte.Solution.Projects) { if (ProjectKind.IsSupportedProjectKind(project.Kind)) { projectList.Add(project); } FindProjectInternal(project.ProjectItems, projectList); } return(projectList); }
private static string GetProjectName(string analyzer, ProjectKind kind) { switch (kind) { case ProjectKind.Core: return(analyzer + ".Analyzers.csproj"); case ProjectKind.CSharp: return(analyzer + ".CSharp.Analyzers.csproj"); case ProjectKind.Setup: return(analyzer + ".Analyzers.Setup.csproj"); case ProjectKind.UnitTests: return(analyzer + ".Analyzers.UnitTests.csproj"); case ProjectKind.VisualBasic: return(analyzer + ".VisualBasic.Analyzers.vbproj"); case ProjectKind.NuGet: return(analyzer + ".Analyzers.NuGet.proj"); } throw new InvalidOperationException(); }
public static Byte ToByte(this ProjectKind projectKind) { switch (projectKind) { case ProjectKind.Standalone_Windows: return(0x41); case ProjectKind.Standalone_Macintosh: return(0x42); case ProjectKind.Embedded_Windows: return(0x43); case ProjectKind.Embedded_Macintosh: return(0x44); default: throw new NotSupportedException(String.Format("ProjectKind {0} not supported", projectKind)); } }
public static void CreateStubFiles(ProjectKind kind, string target, string analyzer, IList<CheckData> checks, Dictionary<string, IEnumerable<string>> categories) { if (kind == ProjectKind.Setup || kind == ProjectKind.NuGet) { return; } foreach (var check in checks) { if (kind == ProjectKind.Core) { Utilities.CreateFile(CodeTemplates.GenerateAnalyzer(analyzer, check), target, CodeTemplates.GenerateAnalyzerFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCodeFix(analyzer, check), target, CodeTemplates.GenerateCodeFixFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCategory(analyzer, categories[analyzer]), target, CodeTemplates.CategoryFileName); } else if (kind == ProjectKind.CSharp) { Utilities.CreateFile(CodeTemplates.GenerateCSharpAnalyzer(analyzer, check), target, CodeTemplates.GenerateCSharpAnalyzerFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCSharpCodeFix(analyzer, check), target, CodeTemplates.GenerateCSharpCodeFixFileName(check)); } else if (kind == ProjectKind.VisualBasic) { Utilities.CreateFile(CodeTemplates.GenerateBasicAnalyzer(analyzer, check), target, CodeTemplates.GenerateBasicAnalyzerFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateBasicCodeFix(analyzer, check), target, CodeTemplates.GenerateBasicCodeFixFileName(check)); } else if (kind == ProjectKind.UnitTests) { Utilities.CreateFile(CodeTemplates.GenerateAnalyzerTests(analyzer, check), target, CodeTemplates.GenerateAnalyzerTestsFileName(check)); Utilities.CreateFile(CodeTemplates.GenerateCodeFixTests(analyzer, check), target, CodeTemplates.GenerateCodeFixTestsFileName(check)); } } }
public async Task <IEnumerable <IMagicProject> > GetProjectsAsync(string pathToSearch, ProjectKind projectKind) { List <IMagicProject> listProjects = new List <IMagicProject>(); if (projectKind == ProjectKind.CSharp) { listProjects.AddRange(await PopulateWithCSharpProjects(pathToSearch)); } if (projectKind == ProjectKind.VisualBasic) { } if (projectKind == ProjectKind.Npm) { listProjects.AddRange(await PopulateWithNpmProjects(pathToSearch)); } return(listProjects); }
/// <summary> /// Parse a solution file /// </summary> /// <param name="filename">The solution file name.</param> /// <returns></returns> public static Solution FromFile(string filename) { if (filename == null) { throw new ArgumentNullException("filename"); } Tracer.Debug("Loading solution {0} ...", filename); Solution solution = new Solution(); solution.FileName = filename; string contents = File.ReadAllText(filename); if (!contents.Contains("Microsoft Visual Studio Solution File, Format Version 9") && !contents.Contains("Microsoft Visual Studio Solution File, Format Version 10")) { throw new UnsupportedFileFormatException(string.Format(CultureInfo.CurrentCulture, Resources.BadSolutionFormat, filename)); } Regex re = new Regex(@"Project\(""(?<ProjectType>{[\w-]+})""\)\s+=\s+""(?<Name>[\w\.]+?)"",\s+""(?<Path>[\w\.\\:]+?)"",\s+""(?<ProjectGuid>{[\w-]+})"".*?EndProject\b", RegexOptions.Singleline); MatchCollection coll = re.Matches(contents); foreach (Match m in coll) { if (m.Success) { Project project = new Project(solution); project.Name = m.Groups["Name"].Value; Tracer.Debug("Found project named {0} in solution file ...", project.Name); project.ProjectType = new Guid(m.Groups["ProjectType"].Value); project.Guid = new Guid(m.Groups["ProjectGuid"].Value); project.Path = Path.Combine(Path.GetDirectoryName(filename), m.Groups["Path"].Value); /* pseudo vc++ references, project dependencies */ Regex projectDependenciesRegex = new Regex(@"ProjectSection\(ProjectDependencies\)\s=\spostProject(?<Data>.*?)EndProjectSection", RegexOptions.Singleline); Match projectDependencyMatch = projectDependenciesRegex.Match(contents, m.Index, m.Length); if (projectDependencyMatch.Success) { string data = projectDependencyMatch.Groups["Data"].Value; string[] lines = data.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string line in lines) { string[] keyVal = line.Split('='); if (keyVal.Length == 2) { // found a project dependency ... store it for now project.AddProjectDependency(keyVal[0].Trim()); } } } if (!File.Exists(project.Path)) { Tracer.Debug("Skipping non-existent project {0}, solution folder ?", project.Name); continue; } ProjectKind kind = Project.GetKind(project.ProjectType); if (kind == ProjectKind.Unknown || kind == ProjectKind.SolutionItems || kind == ProjectKind.Setup) { Tracer.Debug("Skipping project {0} of type {1}, which is currently unsupported", project.Name, kind); continue; } solution.Projects[project.Guid] = project; } } // first chew the entire solution before parsing ... foreach (Project p in solution.Projects.Values) { p.Parse(); } return(solution); }
public static string GetProjectTemplate(this DTE dte, ProjectKind kind, ProjectLanguage lang) { Debug.Assert(dte != null, "GetTemplateRootPath: dte is null"); return string.Format(dte.GetTemplatePath(ProjectTemplates[(int)lang][(int)kind]), "ProjectTemplatesCache"); }
/// <summary> /// Create a new project using specified info /// </summary> /// <param name="dte">dte instance</param> /// <param name="projectName">project name</param> /// <param name="kind">project kind</param> /// <param name="language">project language</param> /// <returns>new created project</returns> public static Project CreateProject( this DTE dte, string solutionPath, string projectName, ProjectKind kind, ProjectLanguage language) { Debug.Assert(dte != null, "CreateProject: Dte is null"); Debug.Assert(!string.IsNullOrEmpty(solutionPath), "!string.IsNullOrEmpty(solutionPath)"); Debug.Assert(!string.IsNullOrEmpty(projectName), "!string.IsNullOrEmpty(projectName)"); Debug.Assert(dte.Solution != null, "CreateProject: dte.Solution must be created by adding project"); var template = GetProjectTemplate(dte, kind, language); // Check if the project directory exists delete it does since AddFromTemplate will throw if the directory exists. var projectDir = Path.Combine(solutionPath, projectName); if (Directory.Exists(projectDir)) { Directory.Delete(projectDir, true); } dte.Solution.AddFromTemplate(template, Path.Combine(solutionPath, projectName), projectName, false); foreach (Project project in dte.Solution.Projects) { if (project.Name.Contains(projectName)) // Venus projects Name is the full path name - so need to use Contains() { return project; } } Debug.Fail("There is no new project created."); return null; }
public static string GetProjectTemplate(this DTE dte, ProjectKind kind, ProjectLanguage lang) { Debug.Assert(dte != null, "GetTemplateRootPath: dte is null"); return(string.Format(dte.GetTemplatePath(ProjectTemplates[(int)lang][(int)kind]), "ProjectTemplatesCache")); }
internal BasePrediction(ProjectKind projectKind, string topIntent) { ProjectKind = projectKind; TopIntent = topIntent; }
private static string GetProjectName(string analyzer, ProjectKind kind) { switch (kind) { case ProjectKind.Core: return analyzer + ".Analyzers.csproj"; case ProjectKind.CSharp: return analyzer + ".CSharp.Analyzers.csproj"; case ProjectKind.Setup: return analyzer + ".Analyzers.Setup.csproj"; case ProjectKind.UnitTests: return analyzer + ".Analyzers.UnitTests.csproj"; case ProjectKind.VisualBasic: return analyzer + ".VisualBasic.Analyzers.vbproj"; case ProjectKind.NuGet: return analyzer + ".Analyzers.NuGet.proj"; } throw new InvalidOperationException(); }
public static void BuildProject( string outputDirectory, string sourceDirectory, string analyzer, ProjectKind kind, IEnumerable<string> copyFiles, IEnumerable<string> renamedFiles, string projectName, Dictionary<string, IEnumerable<string>> categories, Dictionary<string, Dictionary<string, string>> projectGuids, IList<CheckData> checks) { string target = Path.Combine(outputDirectory, "src", analyzer + ".Analyzers", kind.ToString()); Directory.CreateDirectory(target); // Identically named supporting Files string source = Path.Combine(sourceDirectory, "src", "REPLACE.ME", kind.ToString()); foreach (string copiedFile in copyFiles) { Utilities.CopyFile(source, target, copiedFile); } // Everybody gets an assemblyInfo, except vb and nuget if (kind != ProjectKind.VisualBasic && kind != ProjectKind.NuGet) { Directory.CreateDirectory(Path.Combine(target, "Properties")); Utilities.CopyFile(source, target, @"Properties\AssemblyInfo.cs"); } foreach (string renamedFile in renamedFiles) { if (renamedFile == "REPLACEMEAnalyzersResources.resx") { Debug.Assert(kind == ProjectKind.Core); Debug.Assert(checks != null); } Utilities.CopyRenamedFile(source, target, renamedFile, analyzer, checks, categories, projectGuids); } Dictionary<string, string> analyzerGuids; if (!projectGuids.TryGetValue(kind.ToString(), out analyzerGuids)) { projectGuids[kind.ToString()] = analyzerGuids = new Dictionary<string, string>(); } analyzerGuids[analyzer] = Utilities.CopyRenamedFile(source, target, projectName, analyzer, checks, categories, projectGuids); Utilities.CreateStubFiles(kind, target, analyzer, checks, categories); }
Project CreateProject(ProjectKind Kind, Product OriginalProduct) { Project p = new Project(); p.iMonth = MonthID; p.CreatedInSafeMode = this.SafeMode; p.ID = ++lastProjectID; p.OriginalProduct = OriginalProduct; p.iMonthStarted = MonthID; //p.State = (OriginalProduct == null) ? ProjectState.NotStarted : ProjectState.Spec; p.State = ProjectState.NotStarted; p.Kind = Kind; p.FindingStaff += new FindingStaffEventHandler(OnProjectFindingStaff); p.ProjectReleasing += new ProjectReleasingEventHandler(OnProjectReleasing); //ProjectCreated(p); Debug.WriteLine("A new project created. ID = " + p.ID.ToString() + "; Kind = " + p.Kind.ToString()); AllProjects.Add(p); //p.NextMonth(); return p; }
public async Task <IEnumerable <IMagicProject> > GetProjectsAsync(string pathToSearch, ProjectKind projectKind) => await Task.Run(() => { var result = new List <IMagicProject> { new MagicProjectCs(@"C:\SomePath\Sample1.csproj") { ProjectType = FrameworkKind.DOTNET, FrameworkVersion = "v4.7", Packages = new List <IMagicPackage> { new BasicPackage { Name = "System", PackageType = PackageKind.Reference }, new NugetPackage { Name = "GalaSoft.MvvmLight", PackageType = PackageKind.PackageReference }, new NugetPackage { Name = "NewtonSoft.Json", PackageType = PackageKind.PackageConfig }, new NpmPackage { Name = "AnyNpm", PackageType = PackageKind.Npm } } }, new MagicProjectCs(@"C:\SomePath\Sample2.csproj") { ProjectType = FrameworkKind.DOTNET, FrameworkVersion = "v4.7", Packages = new List <IMagicPackage> { new BasicPackage { Name = "System", PackageType = PackageKind.Reference }, new NugetPackage { Name = "GalaSoft.MvvmLight", PackageType = PackageKind.PackageReference }, new NugetPackage { Name = "NewtonSoft.Json", PackageType = PackageKind.PackageConfig }, new NpmPackage { Name = "AnyNpm", PackageType = PackageKind.Npm } } } }; return(result); });
public static char ToChar(this ProjectKind projectKind) { Byte[] bytes = new byte[] { ToByte(projectKind) }; return(Encoding.ASCII.GetChars(bytes).Single()); }