Exemplo n.º 1
0
        public AuditProject(IProject roslynProject, FrameworkName targetFramework, Options options)
        {
            // Shared
            RoslynProject    = roslynProject;
            MsBuildProject   = RoslynProject.GetMsBuildProject();
            LocalRepository  = RoslynProject.Solution.GetLocalPackageRepository();
            ConfigReferences = PackageReferenceFile.CreateFromProject(RoslynProject.FilePath).GetPackageReferences(false).ToList();
            CsprojReferences = MsBuildProject.GetDirectPackageAssemblies().Select(g => g.Key).Where(r => r != null).Distinct().ToList();
            References       = ConfigReferences.Union(CsprojReferences).ToList();
            Packages         = options.Unused || options.Snapshot || options.Missing || options.Project
                ? References.Select(r => r.GetPackage(LocalRepository)).Where(p => p != null).ToList()
                : Enumerable.Empty <IPackage>();
            // Unused Packages
            UnusedPackages = options.Unused
                ? GetUnusedPackages(targetFramework, options.UnusedUsings)
                : Enumerable.Empty <UnusedPackage>();

            // Snapshot References
            SnapshotPackages = options.Snapshot
                ? Packages.GetSnapshotPackages()
                : Enumerable.Empty <SnapshotPackage>();

            // Missing Packages
            MissingPackages = options.Missing
                ? GetMissingPackages(targetFramework)
                : Enumerable.Empty <MissingPackageDependency>();

            // Project Packages
            ProjectPackages = options.Project
                ? GetProjectPackages()
                : Enumerable.Empty <ProjectPackage>();

            // File Diff References
            MissingPackageReferences = options.FileDiff
                ? GetMissingPackageReferences()
                : Enumerable.Empty <InconsistentFiles>();

            // Duplicate Package References
            DuplicatePackageReferences = options.FileDiff
                ? GetDuplicatePackageReferences()
                : Enumerable.Empty <DuplicatePackageReference>();

            // Orphan Binding Redirects
            BindingRedirectOnlyReferences = options.FileDiff
                ? GetBindingRedirectOnlyReferences()
                : Enumerable.Empty <OrphanAssemblyBinding>();

            // Mismatched Binding Redirects
            BindingRedirectMismatchReferences = options.RedirectMismatch
                ? GetBindingRedirectMismatchReferences()
                : Enumerable.Empty <MismatchAssemblyBinding>();

            BadProjectRefGuids = options.FileDiff
                ? GetBadProjectRefGuids()
                : Enumerable.Empty <MismatchedGuid>();

            IllegalNugetTargets = options.NugetTargets
                ? GetIllegalNugetTargets()
                : Enumerable.Empty <IllegalProjectFileElement>();
        }
Exemplo n.º 2
0
        private IEnumerable <DuplicatePackageReference> GetDuplicatePackageReferences()
        {
            var configDuplicates = ConfigReferences
                                   .Duplicates()
                                   .Select(r => new DuplicatePackageReference(r, "packages.config"));

            var csprojDuplicates = MsBuildProject.GetDirectPackageAssemblies()
                                   .SelectMany(p => p, (grouping, s) => new { grouping, s })
                                   .DuplicatesBy(a => a.s)
                                   .Select(r => new DuplicatePackageReference(r.grouping.Key, ".csproj", r.s.Key));

            return(configDuplicates.Concat(csprojDuplicates));
        }
Exemplo n.º 3
0
        private IEnumerable <InconsistentFiles> GetMissingPackageReferences()
        {
            var configOnlyReferences = ConfigReferences.Except(CsprojReferences)
                                                                                       // References in packages.config may not have assemblies, these don't show up in .csproj
                                       .Where(r => r.GetPackage(LocalRepository).AssemblyReferences.Any())
                                       .Where(r => !r.Id.Equals("Microsoft.Net.Http")) // This package is weird, it uses the GAC assembly instead of the one it ships with.
                                       .Select(r => new InconsistentFiles(r, "packages.config"));

            var csprojOnlyReferences = CsprojReferences.Except(ConfigReferences)
                                       .Select(r => new InconsistentFiles(r, ".csproj"));

            return(configOnlyReferences.Union(csprojOnlyReferences));
        }
Exemplo n.º 4
0
        public PackageVersionControl()
        {
            DataContextChanged += (sender, args) =>
            {
                if (args.OldValue != null)
                {
                    ViewModel.PropertyChanged -= ViewModelOnPropertyChanged;
                }
                if (args.NewValue != null)
                {
                    ViewModel.PropertyChanged += ViewModelOnPropertyChanged;
                }
            };

            InitializeComponent();

            Assemblies.RegisterSort(nameof(AssemblyInfo.Name));
            ReferencingPackages.RegisterSort(nameof(IPackageVersion.Package), nameof(IPackage.Name));
            ReferencingProjects.RegisterSort(nameof(IProject.Name));
            ConfigReferences.RegisterSort(nameof(IProject.Name));
            BindingRedirectReferences.RegisterSort(nameof(IProject.Name));
        }