Пример #1
0
        public static void InstallAssembly(string path, InstallReference reference, bool force)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            AssemblyCommitFlags flags;

            flags = force ? AssemblyCommitFlags.ForceRefresh : AssemblyCommitFlags.Refresh;

            FusionInstallReference fusionReference = null;

            if (reference != null)
            {
                if (!reference.CanBeUsed())
                {
                    throw new ArgumentException("InstallReferenceType can not be used", nameof(reference));
                }

                fusionReference =
                    new FusionInstallReference(reference.Type, reference.Identifier, reference.Description);
            }

            var assemblyCache = GetAssemblyCache();

            ComCheck(assemblyCache.InstallAssembly((int)flags, path, fusionReference));
        }
Пример #2
0
        public static UninstallResult UninstallAssembly(AssemblyName assemblyName, InstallReference reference)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException(nameof(assemblyName));
            }
            if (!assemblyName.IsFullyQualified())
            {
                throw new ArgumentOutOfRangeException(nameof(assemblyName), assemblyName,
                                                      "Must be a fully qualified assembly name");
            }

            FusionInstallReference fusionReference = null;

            if (reference != null)
            {
                if (!reference.CanBeUsed())
                {
                    throw new ArgumentException("InstallReferenceType can not be used", nameof(reference));
                }

                fusionReference =
                    new FusionInstallReference(reference.Type, reference.Identifier, reference.Description);
            }

            var assemblyCache = GetAssemblyCache();

            ComCheck(assemblyCache.UninstallAssembly(0, assemblyName.GetFullyQualifiedName(), fusionReference,
                                                     out var disposition));

            return((UninstallResult)disposition);
        }
Пример #3
0
        public static IEnumerable <InstallReference> GetInstallReferences(AssemblyName assemblyName)
        {
            ComCheck(FusionApi.CreateAssemblyNameObject(out var fusionAssemblyName, assemblyName.GetFullyQualifiedName(),
                                                        CreateAssemblyNameObjectFlags.ParseDisplayName, IntPtr.Zero));

            ComCheck(FusionApi.CreateInstallReferenceEnum(out var installReferenceEnum, fusionAssemblyName, 0,
                                                          IntPtr.Zero));

            do
            {
                var hResult = installReferenceEnum.GetNextInstallReferenceItem(out var item, 0, IntPtr.Zero);
                if ((uint)hResult == 0x80070103)  // ERROR_NO_MORE_ITEMS
                {
                    yield break;
                }
                ComCheck(hResult);

                ComCheck(item.GetReference(out var refData, 0, IntPtr.Zero));

                var fusionReference = new FusionInstallReference();
                Marshal.PtrToStructure(refData, fusionReference);

                var reference = new InstallReference(InstallReferenceGuid.ToType(fusionReference.GuidScheme),
                                                     fusionReference.Identifier,
                                                     fusionReference.NonCanonicalData);

                yield return(reference);
            } while (true);
        }