Example #1
0
        public static void Main(string[] args)
        {
            projectPath = (args.Length == 0) ? "./" : args[0];
            if (Directory.GetFiles(projectPath, "*.csproj").Length == 0)
            {
                Console.WriteLine(args.Length == 0 ? "Project not found in current directory" : "Project not found in the directory specified");
                return;
            }
            DateTime startTime = DateTime.UtcNow;

            CommandLineUtils.PrintInfoMessage("Plugin is running... ");
            string projectName = new DirectoryInfo(projectPath).Name;

            RetrieveNugetProperties(string.Format(nugetPropsFile, projectPath, projectName));
            CommandLineUtils.PrintInfoMessage($"Project Name: {projectName}");
            string projectFilePath = Path.Combine(projectPath, string.Format(projectFile, projectName));

            if (TryGetPolicy(out ProjectPolicy policy))
            {
                if (File.Exists(projectFilePath))
                {
                    CommandLineUtils.PrintInfoMessage("Finding project dependencies...  ");
                    List <NuGetPackage> packagesFound = PackageLoader.LoadPackages(projectFilePath, projectAssetsPath)
                                                        .Distinct()
                                                        .ToList();
                    CommandLineUtils.PrintSuccessMessage("Finding project dependencies DONE");
                    CommandLineUtils.PrintInfoMessage("Searching for dependencies licenses and vulnerabilities...  ");
                    List <Dependency> dependenciesEvaluated = ValidateProjectDependencies(packagesFound, policy).Result;
                    CommandLineUtils.PrintSuccessMessage("Searching for dependencies licenses and vulnerabilities DONE");
                    string report = GenerateReport(dependenciesEvaluated, policy);
                    CommandLineUtils.PrintSuccessMessage("Produced report locally.");
                    StoreReport(report);
                    double seconds = (DateTime.UtcNow - startTime).TotalSeconds;
                    CommandLineUtils.PrintInfoMessage("Plugin execution time: " + seconds);
                }
                else
                {
                    CommandLineUtils.PrintErrorMessage($"Packages.config file not found in project {projectName}");
                }
            }
        }