Example #1
0
        /// <summary>
        /// Installs an assembly to the GAC.
        /// </summary>
        /// <param name="assemblyPath">Path to assembly to install.</param>
        /// <param name="reference">Describes the application which is installing the assembly.</param>
        /// <param name="flags">Additional assembly commit flags.</param>
        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 = Fusion.CreateAssemblyCache(out ac, 0);
            if (hr >= 0)
            {
                hr = ac.InstallAssembly((int)flags, assemblyPath, reference);
            }

            if (hr < 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }
        }
Example #2
0
        /// <summary>
        /// Uninstalls an assembly from the GAC.
        /// </summary>
        /// <param name="assemblyName">Fully specified assembly name.</param>
        /// <param name="reference">Application which is uninstalling the assembly.</param>
        /// <returns>Resulting assembly disposition.</returns>
        /// <remarks>
        /// The assemblyName parameter has to be a 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.
        /// </remarks>
        public static AssemblyCacheUninstallDisposition UninstallAssembly(string assemblyName, InstallReference reference)
        {
            var dispResult = AssemblyCacheUninstallDisposition.Uninstalled;

            if (reference != null)
            {
                if (!InstallReferenceGuid.IsValidGuidScheme(reference.GuidScheme))
                {
                    throw new ArgumentException("Invalid reference guid.", "guid");
                }
            }

            IAssemblyCache ac = null;

            int hr = Fusion.CreateAssemblyCache(out ac, 0);

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

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

            return(dispResult);
        }