Beispiel #1
0
        private void AddPackageReferenceWithValidation(MsBuildProject project, PackageReference packageReference, Action <PackageReference> addPackageReference)
        {
            Action action = _packageReferenceConflictChecker.CheckForConflict(project, packageReference) switch
            {
                PackageReferenceConflictResult.NoExisting _ => () => addPackageReference(packageReference),
                PackageReferenceConflictResult.ExistingIsIncompatible result => () => throw new ConflictingPackageReferenceException(packageReference, result.Version),
                      PackageReferenceConflictResult.ExistingIsCompatible _ => Functional.NoOperation,
                      var result => throw new InvalidOperationException($"Enum variant {result.GetType().Name} is not supported"),
            };

            action();
        }
        private static void AddPackageReferences(MsBuildProject packagesProject, IEnumerable <PackageReference> packageReferences)
        {
            var itemGroup = packagesProject.GetItemGroupWithItemOfTypeOrCreateNew(PackageReferenceTypeTag);

            foreach (var packageReference in packageReferences)
            {
                Action action = CheckForConflict(packagesProject, packageReference) switch
                {
                    PackageReferenceConflictResult.NoExisting _ => () => AddPackageReference(itemGroup, packageReference),
                    PackageReferenceConflictResult.ExistingIsCompatible _ => Functional.NoOperation,
                    PackageReferenceConflictResult.ExistingIsIncompatible result => throw new ConflictingPackageReferenceException(packageReference, result.Version),
                          var result => throw new InvalidOperationException($"Enum variant {result.GetType().Name} is not supported"),
                };
                action();
            }
        }