예제 #1
0
        public FUSION_INSTALL_REFERENCE 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;
            FUSION_INSTALL_REFERENCE instRef = new FUSION_INSTALL_REFERENCE(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;
        }
예제 #2
0
        public static void InstallAssembly(String assemblyPath, FUSION_INSTALL_REFERENCE reference, AssemblyCommitFlags flags)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidInstallGuidScheme(reference.GuidScheme))
                    throw new ArgumentException("Invalid reference guid.", "guid");
            }

            IAssemblyCache ac = null;

            int hr = 0;

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

            if (hr < 0)
            {
                if (hr == -2146234300 /*0x80131044*/)
                    throw new AssemblyMustBeStronglyNamedException();
                else
                    Marshal.ThrowExceptionForHR(hr);
            }
        }
예제 #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, FUSION_INSTALL_REFERENCE reference,
                                             out IASSEMBLYCACHE_UNINSTALL_DISPOSITION disp)
        {
            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidUninstallGuidScheme(reference.GuidScheme))
                    throw new ArgumentException("Invalid reference guid.", "guid");
            }

            //  Create an assembly cache objet.
            IAssemblyCache ac = null;
            int hr = FusionImports.CreateAssemblyCache(out ac, 0);
            if (hr < 0)
                Marshal.ThrowExceptionForHR(hr);

            //  Uninstall the assembly.
            hr = ac.UninstallAssembly(0, assemblyName, reference, out disp);
            if (hr < 0)
                Marshal.ThrowExceptionForHR(hr);
        }