Ejemplo n.º 1
0
        public InstallReference GetNextReference()
        {
            IInstallReferenceItem item = null;
            int hr = refEnum.GetNextInstallReferenceItem(out item, 0, IntPtr.Zero);
            if ((uint)hr == 0x80070103) {
                // ERROR_NO_MORE_ITEMS
                return null;
            }

            if (hr < 0) {
                Marshal.ThrowExceptionForHR(hr);
            }

            IntPtr refData;
            var instRef = new InstallReference(Guid.Empty, String.Empty, String.Empty);

            hr = item.GetReference(out refData, 0, IntPtr.Zero);
            if (hr < 0) {
                Marshal.ThrowExceptionForHR(hr);
            }

            Marshal.PtrToStructure(refData, instRef);
            return instRef;
        }
Ejemplo n.º 2
0
        // assemblyName has to be fully specified name.
        // A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        // For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        // If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        public static void UninstallAssembly(String assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp, GACVersion gacVersion = GACVersion.Net40)
        {
            var dispResult = AssemblyCacheUninstallDisposition.Uninstalled;
            if (reference != null) {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme)) {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;
            int hr = 0;

            switch (gacVersion) {
                case GACVersion.Net40:
                    hr = Utils.CreateAssemblyCache40(out ac, 0);
                    break;
                case GACVersion.Net20:
                    hr = Utils.CreateAssemblyCache20(out ac, 0);
                    break;
            }

            if (hr >= 0) {
                hr = ac.UninstallAssembly(0, assemblyName, reference, out dispResult);
            }

            if (hr < 0) {
                Marshal.ThrowExceptionForHR(hr);
            }

            disp = dispResult;
        }
Ejemplo n.º 3
0
        // assemblyName has to be fully specified name.
        // A.k.a, for v1.0/v1.1 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx".
        // For v2.0 assemblies, it should be "name, Version=xx, Culture=xx, PublicKeyToken=xx, ProcessorArchitecture=xx".
        // If assemblyName is not fully specified, a random matching assembly will be uninstalled.
        public static void UninstallAssembly(String assemblyName, InstallReference reference, out AssemblyCacheUninstallDisposition disp)
        {
            AssemblyCacheUninstallDisposition dispResult = AssemblyCacheUninstallDisposition.Uninstalled;
            if (reference != null) {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                    throw new ArgumentException("Invalid reference guid.", "guid");
            }

            IAssemblyCache ac = null;

            int hr = Utils.CreateAssemblyCache(out ac, 0);
            if (hr >= 0) {
                hr = ac.UninstallAssembly(0, assemblyName, reference, out dispResult);
            }

            if (hr < 0) {
                Marshal.ThrowExceptionForHR(hr);
            }

            disp = dispResult;
        }
Ejemplo n.º 4
0
        public static void InstallAssembly(String assemblyPath, InstallReference reference, AssemblyCommitFlags flags, GACVersion gacVersion = GACVersion.Net40)
        {
            if (reference != null) {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme)) {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            int hr = 0;

            switch (gacVersion) {
                case GACVersion.Net40:
                    hr = Utils.CreateAssemblyCache40(out ac, 0);
                    break;
                case GACVersion.Net20:
                    hr = Utils.CreateAssemblyCache20(out ac, 0);
                    break;
            }
            // hr = Utils.CreateAssemblyCache(out ac, 0);
            if (hr >= 0) {
                hr = ac.InstallAssembly((int)flags, assemblyPath, reference);
            }

            if (hr < 0) {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
Ejemplo n.º 5
0
        public static void InstallAssembly(String assemblyPath, InstallReference reference, AssemblyCommitFlags flags)
        {
            if (reference != null) {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                    throw new ArgumentException("Invalid reference guid.", "guid");
            }

            IAssemblyCache ac = null;

            int hr = 0;

            hr = Utils.CreateAssemblyCache(out ac, 0);
            if (hr >= 0) {
                hr = ac.InstallAssembly((int)flags, assemblyPath, reference);
            }

            if (hr < 0) {
                Marshal.ThrowExceptionForHR(hr);
            }
        }