Exemple #1
0
        Import ParseImport(
            HashSet <string> importedFiles, Import import, string projectPath,
            PropertyValueCollector propVals, TaskMetadataBuilder taskBuilder, MSBuildSchemaProvider schemaProvider,
            CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            var           xmlParser = new XmlParser(new XmlRootState(), true);
            ITextDocument textDoc;

            try {
                textDoc = TextEditorFactory.CreateNewDocument(import.Filename, MSBuildTextEditorExtension.MSBuildMimeType);
                xmlParser.Parse(textDoc.CreateReader());
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled error parsing xml document", ex);
                return(import);
            }

            var doc = xmlParser.Nodes.GetRoot();

            import.Document = new MSBuildDocument(import.Filename, false);
            import.Document.Build(
                doc, textDoc, RuntimeInformation, propVals, taskBuilder,
                (imp, sdk) => ResolveImport(importedFiles, null, projectPath, import.Filename, imp, sdk, propVals, taskBuilder, schemaProvider, token)
                );

            import.Document.Schema = schemaProvider.GetSchema(import.Filename, import.Sdk);

            return(import);
        }
Exemple #2
0
        static MSBuildRootDocument ParseDoc(string contents, string filename = "myfile.csproj")
        {
            var runtimeInfo    = new MSBuildEnvironmentRuntimeInformation();
            var textSource     = new StringTextSource(contents);
            var schemaProvider = new MSBuildSchemaProvider();
            var taskBuilder    = new NoopTaskMetadataBuilder();

            return(MSBuildRootDocument.Parse(textSource, filename, null, schemaProvider, runtimeInfo, taskBuilder, default));
        }
Exemple #3
0
 void LoadTasks(
     HashSet <string> importedFiles, MSBuildDocument previous, string filename,
     PropertyValueCollector propVals, TaskMetadataBuilder taskBuilder, MSBuildSchemaProvider schemaProvider,
     CancellationToken token)
 {
     try {
         var import = GetCachedOrParse(importedFiles, previous, filename, null, File.GetLastWriteTimeUtc(filename), Filename, propVals, taskBuilder, schemaProvider, token);
         Imports.Add(filename, import);
     } catch (Exception ex) {
         LoggingService.LogError($"Error loading tasks file {filename}", ex);
     }
 }
Exemple #4
0
 Import GetCachedOrParse(
     HashSet <string> importedFiles, MSBuildDocument oldDoc, string filename, string sdk, DateTime mtimeUtc, string projectPath,
     PropertyValueCollector propVals, TaskMetadataBuilder taskBuilder, MSBuildSchemaProvider schemaProvider,
     CancellationToken token)
 {
     if (oldDoc != null && oldDoc.Imports.TryGetValue(filename, out Import oldImport) && oldImport.TimeStampUtc == mtimeUtc)
     {
         //TODO: check mtimes of descendent imports too
         return(oldImport);
     }
     else
     {
         //TODO: guard against cyclic imports
         return(ParseImport(importedFiles, new Import(filename, sdk, mtimeUtc), projectPath, propVals, taskBuilder, schemaProvider, token));
     }
 }
        public void TextViewCreated(ITextView textView)
        {
            var buffer = (ITextBuffer2)textView.TextBuffer;

            // attach the parser to the buffer and initialize it
            var parser = BackgroundParser <MSBuildParseResult> .GetParser <MSBuildBackgroundParser> (buffer);

            IRuntimeInformation   runtimeInformation  = new MSBuildEnvironmentRuntimeInformation();
            MSBuildSchemaProvider schemaProvider      = new MSBuildSchemaProvider();
            ITaskMetadataBuilder  taskMetadataBuilder = TaskMetadataBuilder;

            parser.Initialize(runtimeInformation, schemaProvider, taskMetadataBuilder);

            //kick off a parse so it's ready when other things need it
            parser.GetOrParseAsync((ITextSnapshot2)buffer.CurrentSnapshot, CancellationToken.None);
        }
 void EnsureInitialized()
 {
     lock (initLocker) {
         if (runtimeInformation != null)
         {
             return;
         }
         try {
             runtimeInformation = new MSBuildEnvironmentRuntimeInformation();
         } catch (Exception ex) {
             LoggingService.LogError("Failed to initialize runtime info for parser", ex);
             runtimeInformation = new NullRuntimeInformation();
         }
         schemaProvider      = new MSBuildSchemaProvider();
         taskMetadataBuilder = new NoopTaskMetadataBuilder();
     }
 }
        public MSBuildBackgroundParser(
            ITextBuffer buffer,
            IRuntimeInformation runtimeInformation,
            MSBuildSchemaProvider schemaProvider,
            ITaskMetadataBuilder taskMetadataBuilder)
        {
            RuntimeInformation  = runtimeInformation ?? throw new ArgumentNullException(nameof(runtimeInformation));
            SchemaProvider      = schemaProvider ?? throw new ArgumentNullException(nameof(schemaProvider));
            TaskMetadataBuilder = taskMetadataBuilder ?? throw new ArgumentNullException(nameof(taskMetadataBuilder));

            XmlParser = XmlBackgroundParser.GetParser(buffer);
            XmlParser.ParseCompleted += XmlParseCompleted;

            if (buffer.Properties.TryGetProperty <ITextDocument> (typeof(ITextDocument), out var doc))
            {
                filepath = doc.FilePath;
                doc.FileActionOccurred += OnFileAction;
            }
        }
        public MSBuildParserContext(
            IRuntimeInformation runtimeInformation,
            MSBuildRootDocument doc,
            MSBuildRootDocument previous,
            HashSet <string> importedFiles,
            string projectPath,
            PropertyValueCollector propVals,
            ITaskMetadataBuilder taskBuilder,
            MSBuildSchemaProvider schemaProvider,
            CancellationToken token)
        {
            RuntimeInformation   = runtimeInformation;
            RootDocument         = doc;
            PreviousRootDocument = previous;
            ImportedFiles        = importedFiles;
            ProjectPath          = projectPath;
            PropertyCollector    = propVals;
            TaskBuilder          = taskBuilder;
            SchemaProvider       = schemaProvider;
            Token = token;

            RuntimeEvaluationContext = new MSBuildRuntimeEvaluationContext(runtimeInformation);
        }
 internal void Initialize(IRuntimeInformation runtimeInformation, MSBuildSchemaProvider schemaProvider, ITaskMetadataBuilder taskMetadataBuilder)
 {
     this.runtimeInformation  = runtimeInformation ?? throw new ArgumentNullException(nameof(runtimeInformation));
     this.schemaProvider      = schemaProvider ?? throw new ArgumentNullException(nameof(schemaProvider));
     this.taskMetadataBuilder = taskMetadataBuilder ?? throw new ArgumentNullException(nameof(taskMetadataBuilder));
 }
Exemple #10
0
        public static MSBuildRootDocument Parse(
            ITextSource textSource, string filePath, MSBuildRootDocument previous,
            MSBuildSchemaProvider schemaProvider, IRuntimeInformation runtimeInfo,
            ITaskMetadataBuilder taskBuilder,
            CancellationToken token)
        {
            var xmlParser = new XmlTreeParser(new XmlRootState());

            var(xdocument, _) = xmlParser.Parse(textSource.CreateReader());

            var propVals = new PropertyValueCollector(true);

            var doc = new MSBuildRootDocument(filePath)
            {
                XDocument          = xdocument,
                Text               = textSource,
                RuntimeInformation = runtimeInfo
            };

            var importedFiles = new HashSet <string> (StringComparer.OrdinalIgnoreCase);

            if (filePath != null)
            {
                try {
                    doc.Schema = previous?.Schema ?? schemaProvider.GetSchema(filePath, null);
                } catch (Exception ex) {
                    LoggingService.LogError("Error loading schema", ex);
                }
                importedFiles.Add(filePath);
            }

            var parseContext = new MSBuildParserContext(
                runtimeInfo,
                doc,
                previous,
                importedFiles,
                filePath,
                propVals,
                taskBuilder,
                schemaProvider,
                token);

            if (filePath != null)
            {
                doc.FileEvaluationContext = new MSBuildFileEvaluationContext(parseContext.RuntimeEvaluationContext, filePath, filePath);
            }
            else
            {
                doc.FileEvaluationContext = parseContext.RuntimeEvaluationContext;
            }

            string MakeRelativeMSBuildPathAbsolute(string path)
            {
                var dir = Path.GetDirectoryName(doc.Filename);

                path = path.Replace('\\', Path.DirectorySeparatorChar);
                return(Path.GetFullPath(Path.Combine(dir, path)));
            }

            Import TryImportFile(string label, string possibleFile)
            {
                try {
                    var fi = new FileInfo(possibleFile);
                    if (fi.Exists)
                    {
                        var imp = parseContext.GetCachedOrParse(label, possibleFile, null, fi.LastWriteTimeUtc);
                        doc.AddImport(imp);
                        return(imp);
                    }
                } catch (Exception ex) when(parseContext.IsNotCancellation(ex))
                {
                    LoggingService.LogError($"Error importing '{possibleFile}'", ex);
                }
                return(null);
            }

            Import TryImportSibling(string ifHasThisExtension, string thenTryThisExtension)
            {
                if (filePath == null)
                {
                    return(null);
                }
                var extension = Path.GetExtension(filePath);

                if (string.Equals(ifHasThisExtension, extension, StringComparison.OrdinalIgnoreCase))
                {
                    var siblingFilename = Path.ChangeExtension(filePath, thenTryThisExtension);
                    return(TryImportFile("(implicit)", siblingFilename));
                }
                return(null);
            }

            void TryImportIntellisenseImports(MSBuildSchema schema)
            {
                foreach (var intellisenseImport in schema.IntelliSenseImports)
                {
                    TryImportFile("(from schema)", MakeRelativeMSBuildPathAbsolute(intellisenseImport));
                }
            }

            try {
                //if this is a targets file, try to import the props _at the top_
                var propsImport = TryImportSibling(".targets", ".props");

                // this currently only happens in the root file
                // it's a quick hack to allow files to get some basic intellisense by
                // importing the files _that they themselves expect to be imported from_.
                // we also try to load them from the sibling props, as a paired targets/props
                // will likely share a schema file.
                var schema = doc.Schema ?? propsImport?.Document?.Schema;
                if (schema != null)
                {
                    TryImportIntellisenseImports(doc.Schema);
                }

                doc.Build(xdocument, textSource, parseContext);

                //if this is a props file, try to import the targets _at the bottom_
                var targetsImport = TryImportSibling(".props", ".targets");

                //and if we didn't load intellisense import already, try to load them from the sibling targets
                if (schema == null && targetsImport?.Document?.Schema != null)
                {
                    TryImportIntellisenseImports(targetsImport.Document.Schema);
                }
            } catch (Exception ex) when(parseContext.IsNotCancellation(ex))
            {
                LoggingService.LogError($"Error building document '{filePath ?? "[unnamed]"}'", ex);
            }

            try {
                var binpath = parseContext.RuntimeInformation.BinPath;
                foreach (var t in Directory.GetFiles(binpath, "*.tasks"))
                {
                    doc.LoadTasks(parseContext, "(core tasks)", t);
                }
                foreach (var t in Directory.GetFiles(binpath, "*.overridetasks"))
                {
                    doc.LoadTasks(parseContext, "(core overridetasks)", t);
                }
            } catch (Exception ex) when(parseContext.IsNotCancellation(ex))
            {
                LoggingService.LogError("Error resolving tasks", ex);
            }

            try {
                if (previous != null)
                {
                    // try to recover some values that may have been collected from the imports, as they
                    // will not have been re-evaluated
                    var fx = previous.Frameworks.FirstOrDefault();
                    if (fx != null)
                    {
                        propVals.Collect("TargetFramework", fx.GetShortFolderName());
                        propVals.Collect("TargetFrameworkVersion", FrameworkInfoProvider.FormatDisplayVersion(fx.Version));
                        propVals.Collect("TargetFrameworkIdentifier", fx.Framework);
                    }
                }
                doc.Frameworks = propVals.GetFrameworks();
            } catch (Exception ex) {
                LoggingService.LogError("Error determining project framework", ex);
                doc.Frameworks = new List <NuGetFramework> ();
            }

            try {
                //this has to run in a second pass so that it runs after all the schemas are loaded
                var validator = new MSBuildDocumentValidator();
                validator.Run(doc.XDocument, textSource, doc);
            } catch (Exception ex) when(parseContext.IsNotCancellation(ex))
            {
                LoggingService.LogError("Error in validation", ex);
            }

            return(doc);
        }
Exemple #11
0
        public static MSBuildRootDocument Parse(
            string filename, ITextSource textSource, MSBuildRootDocument previous,
            MSBuildSchemaProvider schemaProvider, IRuntimeInformation runtimeInfo,
            CancellationToken token)
        {
            var xmlParser = new XmlParser(new XmlRootState(), true);

            try {
                xmlParser.Parse(textSource.CreateReader());
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled error parsing xml document", ex);
            }

            var xdocument = xmlParser.Nodes.GetRoot();

            if (xdocument != null && xdocument.RootElement != null)
            {
                if (!xdocument.RootElement.IsEnded)
                {
                    xdocument.RootElement.End(xmlParser.Location);
                }
            }

            //FIXME: unfortunately the XML parser's regions only have line+col locations, not offsets
            //so we need to create an ITextDocument to extract tag bodies
            //we should fix this by changing the parser to use offsets for the tag locations
            ITextDocument textDoc = textSource as ITextDocument
                                    ?? TextEditorFactory.CreateNewDocument(textSource, filename, MSBuildTextEditorExtension.MSBuildMimeType);

            var propVals = new PropertyValueCollector(true);

            string projectPath = filename;

            var doc = new MSBuildRootDocument(filename)
            {
                XDocument          = xdocument,
                Text               = textDoc,
                RuntimeInformation = runtimeInfo
            };

            doc.Errors.AddRange(xmlParser.Errors);

            try {
                doc.Schema = previous?.Schema ?? schemaProvider.GetSchema(filename, null);
            } catch (Exception ex) {
                LoggingService.LogError("Error loading schema", ex);
            }

            var importedFiles = new HashSet <string> (StringComparer.OrdinalIgnoreCase)
            {
                filename
            };

            var taskBuilder = new TaskMetadataBuilder(doc);

            var extension = Path.GetExtension(filename);

            string MakeRelativeMSBuildPathAbsolute(string path)
            {
                var dir = Path.GetDirectoryName(doc.Filename);

                path = path.Replace('\\', Path.DirectorySeparatorChar);
                return(Path.GetFullPath(Path.Combine(dir, path)));
            }

            Import TryImportFile(string possibleFile)
            {
                try {
                    var fi = new FileInfo(possibleFile);
                    if (fi.Exists)
                    {
                        var imp = doc.GetCachedOrParse(importedFiles, previous, possibleFile, null, fi.LastWriteTimeUtc, projectPath, propVals, taskBuilder, schemaProvider, token);
                        doc.Imports.Add(possibleFile, imp);
                        return(imp);
                    }
                } catch (Exception ex) {
                    LoggingService.LogError($"Error importing '{possibleFile}'", ex);
                }
                return(null);
            }

            Import TryImportSibling(string ifHasThisExtension, string thenTryThisExtension)
            {
                if (string.Equals(ifHasThisExtension, extension, StringComparison.OrdinalIgnoreCase))
                {
                    var siblingFilename = Path.ChangeExtension(filename, thenTryThisExtension);
                    return(TryImportFile(siblingFilename));
                }
                return(null);
            }

            void TryImportIntellisenseImports(MSBuildSchema schema)
            {
                foreach (var intellisenseImport in schema.IntelliSenseImports)
                {
                    TryImportFile(MakeRelativeMSBuildPathAbsolute(intellisenseImport));
                }
            }

            try {
                //if this is a targets file, try to import the props _at the top_
                var propsImport = TryImportSibling(".targets", ".props");

                // this currently only happens in the root file
                // it's a quick hack to allow files to get some basic intellisense by
                // importing the files _that they themselves expect to be imported from_.
                // we also try to load them from the sibling props, as a paired targets/props
                // will likely share a schema file.
                var schema = doc.Schema ?? propsImport?.Document?.Schema;
                if (schema != null)
                {
                    TryImportIntellisenseImports(doc.Schema);
                }

                doc.Build(
                    xdocument, textDoc, runtimeInfo, propVals, taskBuilder,
                    (imp, sdk) => doc.ResolveImport(importedFiles, previous, projectPath, filename, imp, sdk, propVals, taskBuilder, schemaProvider, token)
                    );

                //if this is a props file, try to import the targets _at the bottom_
                var targetsImport = TryImportSibling(".props", ".targets");

                //and if we didn't load intellisense import already, try to load them from the sibling targets
                if (schema == null && targetsImport?.Document?.Schema != null)
                {
                    TryImportIntellisenseImports(targetsImport.Document.Schema);
                }
            } catch (Exception ex) {
                LoggingService.LogError($"Error building document '{projectPath}'", ex);
            }

            try {
                var binpath = doc.RuntimeInformation.GetBinPath();
                foreach (var t in Directory.GetFiles(binpath, "*.tasks"))
                {
                    doc.LoadTasks(importedFiles, previous, t, propVals, taskBuilder, schemaProvider, token);
                }
                foreach (var t in Directory.GetFiles(binpath, "*.overridetasks"))
                {
                    doc.LoadTasks(importedFiles, previous, t, propVals, taskBuilder, schemaProvider, token);
                }
            } catch (Exception ex) {
                LoggingService.LogError("Error resolving tasks", ex);
            }

            try {
                if (previous != null)
                {
                    // try to recover some values that may have been collected from the imports, as they
                    // will not have been re-evaluated
                    var fx = previous.Frameworks.FirstOrDefault();
                    if (fx != null)
                    {
                        propVals.Collect("TargetFramework", fx.GetShortFolderName());
                        propVals.Collect("TargetFrameworkVersion", FrameworkInfoProvider.FormatDisplayVersion(fx.Version));
                        propVals.Collect("TargetFrameworkIdentifier", fx.Framework);
                    }
                }
                doc.Frameworks = propVals.GetFrameworks();
            } catch (Exception ex) {
                LoggingService.LogError("Error determining project framework", ex);
                doc.Frameworks = new List <NuGetFramework> ();
            }

            try {
                //this has to run in a second pass so that it runs after all the schemas are loaded
                var validator = new MSBuildDocumentValidator();
                validator.Run(doc.XDocument, filename, textDoc, doc);
            } catch (Exception ex) {
                LoggingService.LogError("Error in validation", ex);
            }

            return(doc);
        }
Exemple #12
0
        IEnumerable <Import> ResolveImport(HashSet <string> importedFiles, MSBuildRootDocument oldDoc, string projectPath, string thisFilePath, string importExpr, string sdk, PropertyValueCollector propVals, TaskMetadataBuilder taskBuilder, MSBuildSchemaProvider schemaProvider, CancellationToken token)
        {
            //FIXME: add support for MSBuildUserExtensionsPath, the context does not currently support it
            if (importExpr.IndexOf("$(MSBuildUserExtensionsPath)", StringComparison.OrdinalIgnoreCase) > -1)
            {
                yield break;
            }

            //TODO: re-use these contexts instead of recreating them
            var importEvalCtx = MSBuildEvaluationContext.Create(RuntimeInformation, projectPath, thisFilePath);

            bool foundAny   = false;
            bool isWildcard = false;

            //the ToList is necessary because nested parses can alter the list between this yielding values
            foreach (var filename in importEvalCtx.EvaluatePathWithPermutation(importExpr, Path.GetDirectoryName(thisFilePath), propVals).ToList())
            {
                if (string.IsNullOrEmpty(filename))
                {
                    continue;
                }

                //dedup
                if (!importedFiles.Add(filename))
                {
                    foundAny = true;
                    continue;
                }

                //wildcards
                var wildcardIdx = filename.IndexOf('*');

                //arbitrary limit to skip improbably short values from bad evaluation
                const int MIN_WILDCARD_STAR_IDX    = 15;
                const int MIN_WILDCARD_PATTERN_IDX = 10;
                if (wildcardIdx > MIN_WILDCARD_STAR_IDX)
                {
                    isWildcard |= true;
                    var lastSlash = filename.LastIndexOf(Path.DirectorySeparatorChar);
                    if (lastSlash < MIN_WILDCARD_PATTERN_IDX)
                    {
                        continue;
                    }
                    if (lastSlash > wildcardIdx)
                    {
                        continue;
                    }

                    string [] files;
                    try {
                        var dir = filename.Substring(0, lastSlash);
                        if (!Directory.Exists(dir))
                        {
                            continue;
                        }

                        //finding the folder's enough for this to "count" as resolved even if there aren't any files in it
                        foundAny = true;

                        var pattern = filename.Substring(lastSlash + 1);

                        files = Directory.GetFiles(dir, pattern);
                    } catch (Exception ex) {
                        LoggingService.LogError($"Error evaluating wildcard in import candidate '{filename}'", ex);
                        continue;
                    }

                    foreach (var f in files)
                    {
                        Import wildImport;
                        try {
                            wildImport = GetCachedOrParse(importedFiles, oldDoc, f, sdk, File.GetLastWriteTimeUtc(f), projectPath, propVals, taskBuilder, schemaProvider, token);
                        } catch (Exception ex) {
                            LoggingService.LogError($"Error reading wildcard import candidate '{files}'", ex);
                            continue;
                        }
                        yield return(wildImport);
                    }

                    continue;
                }

                Import import;
                try {
                    var fi = new FileInfo(filename);
                    if (!fi.Exists)
                    {
                        continue;
                    }
                    import = GetCachedOrParse(importedFiles, oldDoc, filename, sdk, fi.LastWriteTimeUtc, projectPath, propVals, taskBuilder, schemaProvider, token);
                } catch (Exception ex) {
                    LoggingService.LogError($"Error reading import candidate '{filename}'", ex);
                    continue;
                }

                foundAny = true;
                yield return(import);

                continue;
            }

            // we skip logging for wildcards as these are generally extensibility points that are often unused
            // this is here (rather than being folded into the next condition) for ease of breakpointing
            if (isWildcard)
            {
                foundAny = true;
            }

            if (!foundAny)
            {
                if (oldDoc == null && failedImports.Add(importExpr))
                {
                    LoggingService.LogDebug($"Could not resolve MSBuild import '{importExpr}'");
                }
                yield return(new Import(importExpr, sdk, DateTime.MinValue));
            }
        }
Exemple #13
0
        public static MSBuildRootDocument Parse(
            string filename, ITextSource textSource, MSBuildRootDocument previous,
            MSBuildSchemaProvider schemaProvider, IRuntimeInformation runtimeInfo,
            CancellationToken token)
        {
            var xmlParser = new XmlParser(new XmlRootState(), true);

            try {
                xmlParser.Parse(textSource.CreateReader());
            } catch (Exception ex) {
                LoggingService.LogError("Unhandled error parsing xml document", ex);
            }

            var xdocument = xmlParser.Nodes.GetRoot();

            if (xdocument != null && xdocument.RootElement != null)
            {
                if (!xdocument.RootElement.IsEnded)
                {
                    xdocument.RootElement.End(xmlParser.Location);
                }
            }

            //FIXME: unfortunately the XML parser's regions only have line+col locations, not offsets
            //so we need to create an ITextDocument to extract tag bodies
            //we should fix this by changing the parser to use offsets for the tag locations
            ITextDocument textDoc = textSource as ITextDocument
                                    ?? TextEditorFactory.CreateNewDocument(textSource, filename, MSBuildTextEditorExtension.MSBuildMimeType);

            var propVals = new PropertyValueCollector(true);

            string projectPath = filename;

            var doc = new MSBuildRootDocument(filename);

            doc.XDocument          = xdocument;
            doc.Text               = textDoc;
            doc.RuntimeInformation = runtimeInfo;
            doc.Errors.AddRange(xmlParser.Errors);

            var importedFiles = new HashSet <string> (StringComparer.OrdinalIgnoreCase);

            importedFiles.Add(filename);

            var taskBuilder = new TaskMetadataBuilder(doc);

            try {
                doc.Build(
                    xdocument, textDoc, runtimeInfo, propVals, taskBuilder,
                    (imp, sdk) => doc.ResolveImport(importedFiles, previous, projectPath, filename, imp, sdk, propVals, taskBuilder, schemaProvider, token)
                    );
            } catch (Exception ex) {
                LoggingService.LogError("Error building document", ex);
            }

            try {
                var binpath = doc.RuntimeInformation.GetBinPath();
                foreach (var t in Directory.GetFiles(binpath, "*.tasks"))
                {
                    doc.LoadTasks(importedFiles, previous, t, propVals, taskBuilder, schemaProvider, token);
                }
                foreach (var t in Directory.GetFiles(binpath, "*.overridetasks"))
                {
                    doc.LoadTasks(importedFiles, previous, t, propVals, taskBuilder, schemaProvider, token);
                }
            } catch (Exception ex) {
                LoggingService.LogError("Error resolving tasks", ex);
            }


            try {
                if (previous != null)
                {
                    // try to recover some values that may have been collected from the imports, as they
                    // will not have been re-evaluated
                    var fx = previous.Frameworks.FirstOrDefault();
                    if (fx != null)
                    {
                        propVals.Collect("TargetFramework", fx.GetShortFolderName());
                        propVals.Collect("TargetFrameworkVersion", FrameworkInfoProvider.FormatDisplayVersion(fx.Version));
                        propVals.Collect("TargetFrameworkIdentifier", fx.Framework);
                    }
                }
                doc.Frameworks = propVals.GetFrameworks();
            } catch (Exception ex) {
                LoggingService.LogError("Error determining project framework", ex);
                doc.Frameworks = new List <NuGetFramework> ();
            }

            try {
                doc.Schema = previous?.Schema ?? schemaProvider.GetSchema(filename, null);
            } catch (Exception ex) {
                LoggingService.LogError("Error loading schema", ex);
            }

            try {
                //this has to run in a second pass so that it runs after all the schemas are loaded
                var validator = new MSBuildDocumentValidator();
                validator.Run(doc.XDocument, filename, textDoc, doc);
            } catch (Exception ex) {
                LoggingService.LogError("Error in validation", ex);
            }

            return(doc);
        }