Example #1
0
        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);
        }
Example #2
0
 bool HasImported(MSBuildDocument doc, string filename)
 {
     return(doc
            .GetDescendentImports()
            .FirstOrDefault(i => i.Filename.EndsWith(filename, StringComparison.OrdinalIgnoreCase))
            ?.IsResolved ?? false);
 }
Example #3
0
 public ElementDiagnosticContext(MSBuildDocument document, MSBuildLanguageElement element, Action <MSBuildDiagnostic> reportDiagnostic, CancellationToken cancellationToken)
 {
     Document = document;
     Element  = element;
     this.reportDiagnostic = reportDiagnostic;
     CancellationToken     = cancellationToken;
 }
Example #4
0
 void CheckHash(MSBuildDocument document)
 {
     if (lastDocument?.ImportsHash != document.ImportsHash)
     {
         lastDocument        = document;
         itemCheckerTask     = null;
         propertyCheckerTask = null;
         metadataCheckerTasks.Clear();
     }
 }
Example #5
0
 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)))
                                                               )
                                    ));
     }
 }
Example #6
0
 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)))
                                                                       )
                                        ));
     }
 }
Example #7
0
 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);
         }
     }
 }
Example #8
0
        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);
                    }
                }
            }
        }
Example #9
0
 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);
     }
 }
Example #10
0
 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;
 }
Example #14
0
 public MSBuildAnalysisSession(MSBuildAnalysisContextImpl context, MSBuildDocument document, CancellationToken cancellationToken)
 {
     Context           = context;
     Document          = document;
     CancellationToken = cancellationToken;
 }
Example #15
0
 void AddNode(TreeNavigator treeNavigator, MSBuildDocument document, Func <string, (string prefix, string remaining)?> shorten)
Example #16
0
        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)));
            }
        }
Example #17
0
 public async Task <IEnumerable <ItemInfo> > FindSimilarItems(MSBuildDocument document, string name)
 => GetItems(document, await GetItemChecker(document), name);
Example #18
0
 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;
 }
Example #20
0
 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;
 }