本文整理汇总了C#中AssemblyCache.UninstallAssembly方法的典型用法代码示例。如果您正苦于以下问题:C# AssemblyCache.UninstallAssembly方法的具体用法?C# AssemblyCache.UninstallAssembly怎么用?C# AssemblyCache.UninstallAssembly使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AssemblyCache
的用法示例。
在下文中一共展示了AssemblyCache.UninstallAssembly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CleanCache
/// <summary>
/// Cleans the global assembly cache by uninstaling the insured <see cref="Assemblies"/>.
/// </summary>
/// <exception cref="UnauthorizedAccessException"></exception>
/// <returns>True if the cache has been cleaned; Otherwise, false.</returns>
private bool CleanCache()
{
var gac = new AssemblyCache(_data.Installer);
var failed = false;
foreach (var assembly in _assemblies)
{
if (!AssemblyCache.IsInstalled(assembly))
continue;
var disposition = gac.UninstallAssembly(assembly);
failed = disposition == UninstallDisposition.HasReferences || disposition == UninstallDisposition.StillInUse
? true
: failed;
}
return !failed;
}
示例2: Main
/// <summary>
/// Main entry point for <see cref="AppStract.Watcher"/> processes.
/// </summary>
/// <param name="args"></param>
static void Main(string[] args)
{
#if DEBUG
Console.Write("Do you want to attach a debugger? (y)\t");
if (Console.ReadKey().KeyChar == 'y')
Debugger.Break();
Console.WriteLine();
Console.WriteLine();
#endif
_parameters = new Parameters(args);
ReportMessage("Watching with the following parameters:");
ReportMessage(" Flags\t" + _parameters.Flags);
ReportMessage(" File\t\t" + _parameters.InsuranceFile);
ReportMessage(" Registry\t" + _parameters.InsuranceRegistryKey);
ReportMessage(" Insurance\t" + _parameters.InsuranceId);
ReportMessage(" Process\t" + _parameters.ProcessId);
if (!_parameters.Flags.IsSpecified(CleanUpInsuranceFlags.ByWatchService))
{
ReportMessage("A watch service is not required");
#if DEBUG
ReportMessage("Press any key to exit...");
Console.ReadKey();
#endif
return;
}
if (_parameters.InsuranceId != Guid.Empty)
_cleanUpInsurance = CleanUpInsurance.LoadFromSystem(_parameters.InsuranceFile, _parameters.InsuranceRegistryKey,
_parameters.InsuranceId);
if (_cleanUpInsurance == null)
{
ReportMessage("Can't read the required data for IID." + _parameters.InsuranceId +
" from \"" + _parameters.InsuranceFile + "\" or \"" + _parameters.InsuranceRegistryKey + "\"");
#if DEBUG
ReportMessage("Press any key to exit...");
Console.ReadKey();
#endif
return;
}
ReportMessage("The insurance has been read from the system");
// If allowed, clean up the file or registry key used to pass data to the current watcher.
_cleanUpInsurance.Dispose((!_parameters.Flags.IsSpecified(CleanUpInsuranceFlags.TrackByFile)
? CleanUpInsuranceFlags.TrackByFile
: CleanUpInsuranceFlags.None)
| (!_parameters.Flags.IsSpecified(CleanUpInsuranceFlags.TrackByRegistry)
? CleanUpInsuranceFlags.TrackByRegistry
: CleanUpInsuranceFlags.None));
ReportMessage("Retrieving a handle for the process with PID." + _parameters.ProcessId);
try
{
var process = Process.GetProcessById(_parameters.ProcessId);
ReportMessage("Waiting for the process to exit...");
process.WaitForExit();
ReportMessage("Process has exited");
}
catch (Exception e)
{
#if DEBUG
ReportMessage("Failed to get a handle for the process or to wait for the process to exit:\r\n" + e);
ReportMessage("Do you want to CANCEL the clean up procedure? (y)");
if (Console.ReadKey().KeyChar == 'y')
return;
#endif
}
ReportMessage("Invoking cleanup procedure...");
var failed = false;
try
{
var cache = new AssemblyCache(_cleanUpInsurance.Installer);
foreach (var assembly in _cleanUpInsurance.Assemblies)
{
var disposition = cache.UninstallAssembly(assembly);
ReportMessage(" [" + disposition + "] " + assembly.FullName);
failed = disposition == UninstallDisposition.HasReferences || disposition == UninstallDisposition.StillInUse
? true
: failed;
}
ReportMessage("Finished cleanup procedure");
}
catch (UnauthorizedAccessException e)
{
ReportMessage("FAILED to uninstall any of the following assemblies...");
foreach (var assembly in _cleanUpInsurance.Assemblies)
ReportMessage(" " + assembly.FullName);
ReportMessage("\n" + e + "\n");
#if DEBUG
ReportMessage("Press any key to exit...");
Console.ReadKey();
#endif
return;
}
if (!failed)
{
ReportMessage("Disposing insurance...");
_cleanUpInsurance.Dispose();
ReportMessage("Insurance is disposed");
}
//.........这里部分代码省略.........