Пример #1
0
        public static IEnumerable <InstallReference> GetInstallReferences(AssemblyName assemblyName)
        {
            IAssemblyName fusionAssemblyName = null;

            ComCheck(FusionApi.CreateAssemblyNameObject(out fusionAssemblyName, assemblyName.GetFullyQualifiedName(), CreateAssemblyNameObjectFlags.ParseDisplayName, IntPtr.Zero));

            IInstallReferenceEnum installReferenceEnum = null;

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

            IInstallReferenceItem item = null;

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

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

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

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

                yield return(reference);
            } while (true);
        }
Пример #2
0
        public static void InstallAssembly(String path, InstallReference reference, bool force)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            AssemblyCommitFlags flags;

            if (force)
            {
                flags = AssemblyCommitFlags.ForceRefresh;
            }
            else
            {
                flags = AssemblyCommitFlags.Refresh;
            }

            FusionInstallReference fusionReference = null;

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

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

            var assemblyCache = GetAssemblyCache();

            ComCheck(assemblyCache.InstallAssembly((int)flags, path, fusionReference));
        }
Пример #3
0
        public static UninstallResult UninstallAssembly(AssemblyName assemblyName, InstallReference reference)
        {
            if (assemblyName == null)
            {
                throw new ArgumentNullException("assemblyName");
            }
            if (!assemblyName.IsFullyQualified())
            {
                throw new ArgumentOutOfRangeException("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", "reference");
                }

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

            var assemblyCache = GetAssemblyCache();

            AssemblyCacheUninstallDisposition disposition = AssemblyCacheUninstallDisposition.Uninstalled;

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

            return((UninstallResult)disposition);
        }