internal static void Convert(string projectFilePath, Dictionary <string, string> packageMap) { var doc = XDocument.Load(projectFilePath); var msbuildDoc = new MSBuildDocument(doc); var tf = msbuildDoc.XPathSelectElements("TargetFramework").FirstOrDefault(); if (tf != null) { return; } Console.WriteLine($"Processing {Path.GetFileName(projectFilePath)}"); var versionName = msbuildDoc.Namespace.GetName("Version"); foreach (var packageRef in msbuildDoc.XPathSelectElements("PackageReference")) { var version = packageRef.Element(versionName); var value = version.Value.Trim(); if (value.StartsWith("$(")) { value = value.Substring(2, value.Length - 3); var rawVersion = packageMap[value]; version.Value = rawVersion; } } doc.Save(projectFilePath); }
bool HasImported(MSBuildDocument doc, string filename) { return(doc .GetDescendentImports() .FirstOrDefault(i => i.Filename.EndsWith(filename, StringComparison.OrdinalIgnoreCase)) ?.IsResolved ?? false); }
public ElementDiagnosticContext(MSBuildDocument document, MSBuildLanguageElement element, Action <MSBuildDiagnostic> reportDiagnostic, CancellationToken cancellationToken) { Document = document; Element = element; this.reportDiagnostic = reportDiagnostic; CancellationToken = cancellationToken; }
void CheckHash(MSBuildDocument document) { if (lastDocument?.ImportsHash != document.ImportsHash) { lastDocument = document; itemCheckerTask = null; propertyCheckerTask = null; metadataCheckerTasks.Clear(); } }
Task <SpellChecker> GetItemChecker(MSBuildDocument document) { lock (locker) { CheckHash(document); return(itemCheckerTask ?? (itemCheckerTask = Task.Run(() => new SpellChecker( Checksum.Null, document.GetSchemas().GetItems().Select(i => new StringSlice(i.Name))) ) )); } }
Task <SpellChecker> GetPropertyChecker(MSBuildDocument document) { lock (locker) { CheckHash(document); return(propertyCheckerTask ?? (propertyCheckerTask = Task.Run(() => new SpellChecker( Checksum.Null, document.GetSchemas().GetProperties(true).Select(p => new StringSlice(p.Name))) ) )); } }
IEnumerable <ItemInfo> GetItems(MSBuildDocument document, SpellChecker checker, string name) { foreach (var match in checker.FindSimilarWords(name)) { if (string.Equals(match, name, StringComparison.OrdinalIgnoreCase)) { continue; } if (document.GetSchemas().GetItem(match) is ItemInfo info) { yield return(info); } } }
static IEnumerable <Import> GetAllImports(MSBuildDocument doc) { foreach (var import in doc.Imports) { yield return(import); if (import.IsResolved) { foreach (var childImport in GetAllImports(import.Document)) { yield return(childImport); } } } }
Task <SpellChecker> GetMetadataChecker(MSBuildDocument document, string itemName) { lock (locker) { CheckHash(document); if (!metadataCheckerTasks.TryGetValue(itemName, out var checker)) { metadataCheckerTasks[itemName] = checker = Task.Run(() => new SpellChecker( Checksum.Null, document.GetSchemas().GetMetadata(itemName, true).Select(p => new StringSlice(p.Name))) ); } return(checker); } }
internal MSBuildFixContext( ITextBuffer buffer, MSBuildDocument document, XDocument xDocument, TextSpan span, ImmutableArray <MSBuildDiagnostic> diagnostics, Action <MSBuildAction, ImmutableArray <MSBuildDiagnostic> > reportFix, CancellationToken cancellationToken) { this.Buffer = buffer; this.reportFix = reportFix; Document = document; XDocument = xDocument; Span = span; Diagnostics = diagnostics; CancellationToken = cancellationToken; }
public ExpressionNodeDiagnosticContext(MSBuildDocument document, Action <MSBuildDiagnostic> reportDiagnostic, CancellationToken cancellationToken) { Document = document; this.reportDiagnostic = reportDiagnostic; CancellationToken = cancellationToken; }
public static string GetDescription(BaseInfo info, MSBuildDocument doc, MSBuildResolveResult rr) { if (doc == null) { return(info.Description.Text); } //construct a customized version of the include/exclude/etc attribute if appropriate if (info is MSBuildLanguageAttribute att) { switch (att.Name.ToLower()) { case "include": case "exclude": case "remove": case "update": var item = doc.GetSchemas().GetItem(rr.ElementName); if (item != null && !string.IsNullOrEmpty(item.IncludeDescription)) { switch (item.ValueKind) { case MSBuildValueKind.File: case MSBuildValueKind.Folder: case MSBuildValueKind.FolderWithSlash: case MSBuildValueKind.FileOrFolder: return(GetDesc($"Item.{att.Name}.ParameterizedFiles")); default: if (!item.ValueKind.AllowLists()) { return(GetDesc($"Item.{att.Name}.ParameterizedSingle")); } return(GetDesc($"Item.{att.Name}.Parameterized")); } } string GetDesc(string id) => string.Format( ElementDescriptions.ResourceManager.GetString(id, ElementDescriptions.Culture), item.IncludeDescription); break; } } if (info.Description.IsEmpty) { switch (info) { case PropertyInfo prop: if (info.Name.EndsWith("DependsOn", StringComparison.OrdinalIgnoreCase)) { var targetName = info.Name.Substring(0, info.Name.Length - "DependsOn".Length); return($"The targets that the {targetName} target depends on"); } break; case FrameworkInfo fxi: return(FrameworkInfoProvider.GetDescription(fxi.Reference)); } } return(info.Description.Text); }
public MSBuildRefactoringContext(MSBuildDocument document, Action <MSBuildAction> reportRefactoring, CancellationToken cancellationToken) { this.reportRefactoring = reportRefactoring; Document = document; CancellationToken = cancellationToken; }
public MSBuildAnalysisSession(MSBuildAnalysisContextImpl context, MSBuildDocument document, CancellationToken cancellationToken) { Context = context; Document = document; CancellationToken = cancellationToken; }
void AddNode(TreeNavigator treeNavigator, MSBuildDocument document, Func <string, (string prefix, string remaining)?> shorten)
static void FindReferences( MSBuildReferenceCollector collector, SearchProgressMonitor monitor, string filename, XDocument xDocument, IReadonlyTextDocument textDocument, MSBuildDocument doc) { collector.Run(xDocument, filename, textDocument, doc); var fileProvider = new FileProvider(filename); if (collector.Results.Count > 0) { monitor.ReportResults(collector.Results.Select(r => new SearchResult(fileProvider, r.Offset, r.Length))); } }
public async Task <IEnumerable <ItemInfo> > FindSimilarItems(MSBuildDocument document, string name) => GetItems(document, await GetItemChecker(document), name);
public async Task <IEnumerable <PropertyInfo> > FindSimilarProperties(MSBuildDocument document, string name) => GetProperties(document, await GetPropertyChecker(document), name);
public ResolvedAttributeDiagnosticContext(MSBuildDocument document, Action <MSBuildDiagnostic> reportDiagnostic, CancellationToken cancellationToken) { Document = document; this.reportDiagnostic = reportDiagnostic; CancellationToken = cancellationToken; }
public async Task <IEnumerable <MetadataInfo> > FindSimilarMetadata(MSBuildDocument document, string itemName, string name) => GetMetadata(document, await GetMetadataChecker(document, itemName), itemName, name);
public UnknownElementDiagnosticContext(MSBuildDocument document, Action <MSBuildDiagnostic> reportDiagnostic, CancellationToken cancellationToken) { Document = document; this.reportDiagnostic = reportDiagnostic; CancellationToken = cancellationToken; }
public MSBuildFixContext(MSBuildDocument document, Action <MSBuildAction, ImmutableArray <MSBuildDiagnostic> > reportFix, CancellationToken cancellationToken) { this.reportFix = reportFix; Document = document; CancellationToken = cancellationToken; }