internal static bool RemovePackage(string name) { if (string.IsNullOrEmpty(name)) { throw new NullReferenceException($"{nameof(name)} cannot be null"); } string loadedPackage = WebApplicationFactory.GetCurrentLoadedApplicationStorePackageName(); if (!string.IsNullOrEmpty(loadedPackage) && name == loadedPackage) { ConsoleHelper.WriteError($"Cannot delete package '{name}': package is still opened"); return(false); } string currentPackage = ListPackagesStorageFile().FirstOrDefault(p => Path.GetFileName(p) == name); if (currentPackage == null) { ConsoleHelper.WriteError("Package '{name}' not found"); return(false); } try { File.Delete(currentPackage); } catch (Exception ex) { ConsoleHelper.WriteException(ex); return(false); } return(true); }
public bool RemovePackage(string name) { if (string.IsNullOrEmpty(name)) { throw new NullReferenceException($"{nameof(name)} cannot be null"); } string loadedPackage = WebApplicationFactory.GetCurrentLoadedApplicationStorePackageName(); if (!string.IsNullOrEmpty(loadedPackage) && name == loadedPackage) { ConsoleHelper.WriteError($"Cannot delete package '{name}': package is still opened"); return(false); } StorageFile currentPackage = ListPackagesStorageFile().FirstOrDefault(p => p.Name == name); if (currentPackage == null) { ConsoleHelper.WriteError("Package '{name}' not found"); return(false); } try { currentPackage.DeleteAsync(StorageDeleteOption.PermanentDelete).AsTask().ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception ex) { ConsoleHelper.WriteException(ex); return(false); } return(true); }