Beispiel #1
0
        private static async Task DeletePackageAsync()
        {
            try
            {
                // This code region is referenced by the NuGet docs. Please update the docs if you rename the region
                // or move it to a different file.
                #region DeletePackage
                ILogger           logger            = NullLogger.Instance;
                CancellationToken cancellationToken = CancellationToken.None;

                SourceCacheContext    cache      = new SourceCacheContext();
                SourceRepository      repository = Repository.Factory.GetCoreV3("https://api.nuget.org/v3/index.json");
                PackageUpdateResource resource   = await repository.GetResourceAsync <PackageUpdateResource>();

                string apiKey = "my-api-key";

                await resource.Delete(
                    "MyPackage",
                    "1.0.0-beta",
                    getApiKey : packageSource => apiKey,
                    confirm : packageSource => true,
                    noServiceEndpoint : false,
                    logger);

                #endregion
            }
            catch (Exception e)
            {
                Console.WriteLine($"Deleting package failed: {e}");
            }
        }
Beispiel #2
0
    private static async Task DeleteVersionsOfPackage(Options options, string id, IReadOnlyList <string> versions)
    {
        var logger            = NullLogger.Instance;
        var cancellationToken = CancellationToken.None;

        Console.WriteLine($"Unlisting versions for {id} (wait time between request: {options.DelayBetweenRequests} seconds):");
        foreach (var version in versions)
        {
            Console.WriteLine($"  {version}");
            await Task.Delay(options.DelayBetweenRequests * 1000);

            await updateResource.Delete(
                id,
                version,
                getApiKey : packageSource => options.ApiKey,
                confirm : packageSource => true,
                noServiceEndpoint : false,
                logger);
        }
    }
Beispiel #3
0
        public static async Task Run(
            ISettings settings,
            IPackageSourceProvider sourceProvider,
            string packageId,
            string packageVersion,
            string source,
            string apiKey,
            bool nonInteractive,
            Func <string, bool> confirmFunc,
            ILogger logger)
        {
            source = CommandRunnerUtility.ResolveSource(sourceProvider, source);

            PackageUpdateResource packageUpdateResource = await CommandRunnerUtility.GetPackageUpdateResource(sourceProvider, source);

            await packageUpdateResource.Delete(
                packageId,
                packageVersion,
                (endpoint) => CommandRunnerUtility.GetApiKey(settings, endpoint, apiKey),
                (desc) => nonInteractive?true : confirmFunc(desc),
                logger);
        }