Пример #1
0
        private static void LoadDesignTimeBuildFromBuildLogFile(Package package, FileSystemInfo binLog)
        {
            var projectFile = package.GetProjectFile();

            if (projectFile != null &&
                binLog.LastWriteTimeUtc >= projectFile.LastWriteTimeUtc)
            {
                var manager = new AnalyzerManager();
                var results = manager.Analyze(binLog.FullName);

                if (results.Count == 0)
                {
                    throw new InvalidOperationException("The build log seems to contain no solutions or projects");
                }

                var result = results.FirstOrDefault(p => p.ProjectFilePath == projectFile.FullName);
                if (result != null)
                {
                    package.RoslynWorkspace       = null;
                    package.DesignTimeBuildResult = result;
                    package.LastDesignTimeBuild   = binLog.LastWriteTimeUtc;
                    if (result.Succeeded && !binLog.Name.EndsWith(DesignTimeBuildBinlogFileName))
                    {
                        package.LastSuccessfulBuildTime = binLog.LastWriteTimeUtc;
                        if (package.DesignTimeBuildResult.TryGetWorkspace(out var ws))
                        {
                            package.RoslynWorkspace = ws;
                        }
                    }
                }
            }
        }
        static async Task <AnalyzerResult[]> GetAnalyzerResults(AnalyzerManager analyzerManager, string csprojPath, params string[] preprocessorSymbols)
        {
            var tempPath = Path.Combine(new FileInfo(csprojPath).Directory.FullName, "__buildtemp");

            try
            {
                if (!await TryExecute(csprojPath, tempPath, true).ConfigureAwait(false))
                {
                    Console.WriteLine("execute `dotnet msbuild` failed, retry with `msbuild`");
                    if (!await TryExecute(csprojPath, tempPath, false).ConfigureAwait(false))
                    {
                        throw new Exception("failed to build project");
                    }
                }
                // get results of analysis from binarylog
                return(analyzerManager.Analyze(Path.Combine(tempPath, "build.binlog")).ToArray());
            }
            finally
            {
                if (Directory.Exists(tempPath))
                {
                    Directory.Delete(tempPath, true);
                }
            }
        }
Пример #3
0
        private async Task <AnalyzerResults> TryLoadAnalyzerResultsAsync(FileInfo binLog)
        {
            AnalyzerResults results = null;
            await binLog.DoWhenFileAvailable(() =>
            {
                var manager = new AnalyzerManager();
                results     = manager.Analyze(binLog.FullName);
            });

            return(results);
        }
        public void GetsSourceFilesFromBinLogFile(string path, int expectedVersion)
        {
            // Verify this is the expected version
            path = Path.GetFullPath(
                Path.Combine(
                    Path.GetDirectoryName(typeof(SimpleProjectsFixture).Assembly.Location),
                    "..",
                    "..",
                    "..",
                    "..",
                    "binlogs",
                    path))
                   .Replace('\\', Path.DirectorySeparatorChar);
            EnvironmentOptions options = new EnvironmentOptions();

            using (Stream stream = File.OpenRead(path))
            {
                using (GZipStream gzip = new GZipStream(stream, CompressionMode.Decompress))
                {
                    using (BinaryReader reader = new BinaryReader(gzip))
                    {
                        reader.ReadInt32().ShouldBe(expectedVersion);
                    }
                }
            }

            // Given
            StringWriter    log             = new StringWriter();
            AnalyzerManager analyzerManager = new AnalyzerManager(
                new AnalyzerManagerOptions
            {
                LogWriter = log
            });

            // When
            IAnalyzerResults       analyzerResults = analyzerManager.Analyze(path);
            IReadOnlyList <string> sourceFiles     = analyzerResults.First().SourceFiles;

            // Then
            sourceFiles.ShouldNotBeNull(log.ToString());
            new[]
            {
#if Is_Windows
                // Linux and Mac builds appear to omit the AssemblyAttributes.cs file
                "AssemblyAttributes",
#endif
                "Class1",
                "AssemblyInfo"
            }.ShouldBeSubsetOf(sourceFiles.Select(x => Path.GetFileName(x).Split('.').TakeLast(2).First()), log.ToString());
        }
Пример #5
0
        public void Execute(string line)
        {
            Messenger.Trace($"Input string {line}");
            var package = AnalyzerManager.Analyze(line);

            Messenger.Trace("Trying find command");
            if (CommandManager.TryFoundCommand(package.Command, out var command))
            {
                command.Execute(package);
            }
            else
            {
                Messenger.Fatal("Command not found");
            }
        }