/// <summary> /// Resolves XML node references</summary> protected override void ResolveReferences() { base.ResolveReferences(); if (!UnresolvedReferences.Any()) { return; } // look up nodes that have "guid" attribute var nodeGuidDictionary = new Dictionary <string, DomNode>(); foreach (var node in Root.Subtree) { var guidAttr = node.Type.GetAttributeInfo("guid"); if (guidAttr == null) { continue; } var guidStr = node.GetAttribute(guidAttr) as string; if (!string.IsNullOrEmpty(guidStr)) { nodeGuidDictionary[guidStr] = node; } } // resolve template references by GUIDs foreach (var nodeReference in UnresolvedReferences) { if (nodeReference.AttributeInfo.Name == "guidRef") { DomNode refNode; if (nodeGuidDictionary.TryGetValue(nodeReference.Value, out refNode)) { nodeReference.Node.SetAttribute(nodeReference.AttributeInfo, refNode); } else { Outputs.Write(OutputMessageType.Error, "Couldn't resolve node reference by GUID: " + nodeReference.Value); // if DomNode is a template reference, create a missing template if (nodeReference.Node.Type == moduleTemplateRefType.Type || nodeReference.Node.Type == groupTemplateRefType.Type) { var templateNode = GetOrCreateMissingTemplateNode(nodeReference.Value); nodeReference.Node.SetAttribute(nodeReference.AttributeInfo, templateNode); } } } } }
/// <summary> /// Performs a C# build analysis. /// </summary> /// <param name="options">Analysis options from the command line.</param> /// <param name="progress">Display of analysis progress.</param> public BuildAnalysis(Options options, IProgressMonitor progress) { var startTime = DateTime.Now; progressMonitor = progress; var sourceDir = new DirectoryInfo(options.SrcDir); progressMonitor.FindingFiles(options.SrcDir); allSources = sourceDir.GetFiles("*.cs", SearchOption.AllDirectories) .Select(d => d.FullName) .Where(d => !options.ExcludesFile(d)) .ToArray(); var dllDirNames = options.DllDirs.Select(Path.GetFullPath).ToList(); packageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName)); if (options.UseNuGet) { try { var nuget = new NugetPackages(sourceDir.FullName, packageDirectory); nuget.InstallPackages(progressMonitor); } catch (FileNotFoundException) { progressMonitor.MissingNuGet(); } } // Find DLLs in the .Net Framework if (options.ScanNetFrameworkDlls) { var runtimeLocation = Runtime.GetRuntime(options.UseSelfContainedDotnet); progressMonitor.Log(Util.Logging.Severity.Debug, $"Runtime location selected: {runtimeLocation}"); dllDirNames.Add(runtimeLocation); } // These files can sometimes prevent `dotnet restore` from working correctly. using (new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories))) using (new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories))) { var solutions = options.SolutionFile is not null ? new[] { options.SolutionFile } : sourceDir.GetFiles("*.sln", SearchOption.AllDirectories).Select(d => d.FullName); if (options.UseNuGet) { RestoreSolutions(solutions); } dllDirNames.Add(packageDirectory.DirInfo.FullName); assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress); AnalyseSolutions(solutions); foreach (var filename in assemblyCache.AllAssemblies.Select(a => a.Filename)) { UseReference(filename); } } ResolveConflicts(); if (options.UseMscorlib) { UseReference(typeof(object).Assembly.Location); } // Output the findings foreach (var r in usedReferences.Keys) { progressMonitor.ResolvedReference(r); } foreach (var r in unresolvedReferences) { progressMonitor.UnresolvedReference(r.Key, r.Value); } progressMonitor.Summary( AllSourceFiles.Count(), ProjectSourceFiles.Count(), MissingSourceFiles.Count(), ReferenceFiles.Count(), UnresolvedReferences.Count(), conflictedReferences, succeededProjects + failedProjects, failedProjects, DateTime.Now - startTime); }
/// <summary> /// Performs a C# build analysis. /// </summary> /// <param name="options">Analysis options from the command line.</param> /// <param name="progress">Display of analysis progress.</param> public BuildAnalysis(Options options, IProgressMonitor progress) { progressMonitor = progress; sourceDir = new DirectoryInfo(options.SrcDir); progressMonitor.FindingFiles(options.SrcDir); allSources = sourceDir.GetFiles("*.cs", SearchOption.AllDirectories). Select(d => d.FullName). Where(d => !options.ExcludesFile(d)). ToArray(); var dllDirNames = options.DllDirs.Select(Path.GetFullPath); if (options.UseNuGet) { nuget = new NugetPackages(sourceDir.FullName); ReadNugetFiles(); dllDirNames = dllDirNames.Concat(Enumerators.Singleton(nuget.PackageDirectory)); } // Find DLLs in the .Net Framework if (options.ScanNetFrameworkDlls) { dllDirNames = dllDirNames.Concat(Runtime.Runtimes.Take(1)); } assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress); // Analyse all .csproj files in the source tree. if (options.SolutionFile != null) { AnalyseSolution(options.SolutionFile); } else if (options.AnalyseCsProjFiles) { AnalyseProjectFiles(); } if (!options.AnalyseCsProjFiles) { usedReferences = new HashSet <string>(assemblyCache.AllAssemblies.Select(a => a.Filename)); } ResolveConflicts(); if (options.UseMscorlib) { UseReference(typeof(object).Assembly.Location); } // Output the findings foreach (var r in usedReferences) { progressMonitor.ResolvedReference(r); } foreach (var r in unresolvedReferences) { progressMonitor.UnresolvedReference(r.Key, r.Value); } progressMonitor.Summary( AllSourceFiles.Count(), ProjectSourceFiles.Count(), MissingSourceFiles.Count(), ReferenceFiles.Count(), UnresolvedReferences.Count(), conflictedReferences, succeededProjects + failedProjects, failedProjects); }