private async Task <bool> PushAsync( IEnumerable <string> items, PushOptions options) { LocalSettings settings = GetSettings(); SleetLogger log = new SleetLogger(Log, NuGet.Common.LogLevel.Verbose); var packagesToPush = items.ToList(); // Create a separate LocalCache to use for read only operations on the feed. // Files added to the cache before the lock could be modified by the process // currently holding the lock. Sleet assumes that files in the cache // are valid and identical to the ones on the feed since operations are // normally performed inside the lock. using (var preLockCache = CreateFileCache()) { var preLockFileSystem = GetAzureFileSystem(preLockCache); if (!options.AllowOverwrite && options.PassIfExistingItemIdentical) { var context = new SleetContext { LocalSettings = settings, Log = log, Source = preLockFileSystem, Token = CancellationToken }; context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault( context.Source, context.Log, context.Token); var flatContainer = new FlatContainer(context); var packageIndex = new PackageIndex(context); // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet. for (int i = packagesToPush.Count - 1; i >= 0; i--) { string item = packagesToPush[i]; bool?identical = await IsPackageIdenticalOnFeedAsync( item, packageIndex, context.Source, flatContainer, log); if (identical == null) { continue; } packagesToPush.RemoveAt(i); if (identical == true) { Log.LogMessage( MessageImportance.Normal, "Package exists on the feed, and is verified to be identical. " + $"Skipping upload: '{item}'"); } else { Log.LogError( "Package exists on the feed, but contents are different. " + $"Upload failed: '{item}'"); } } if (!packagesToPush.Any()) { Log.LogMessage("After skipping idempotent uploads, no items need pushing."); return(true); } } } // Create a new cache to be used once a lock is obtained. using (var fileCache = CreateFileCache()) { var lockedFileSystem = GetAzureFileSystem(fileCache); return(await PushCommand.RunAsync( settings, lockedFileSystem, packagesToPush, options.AllowOverwrite, skipExisting : false, log : log)); } }
public async Task NuGetReader_PackageMetadataResourceAsync() { // Arrange using (var sourceCacheContext = new SourceCacheContext()) using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var outputRoot = Path.Combine(target.Root, "output"); var baseUri = UriUtility.CreateUri("https://localhost:8080/testFeed/"); var log = new TestLogger(); var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0", Authors = "author", Description = "desc", IconUrl = "http://www.tempuri.org/", Icon = "icon.png", Language = "en-us", MinClientVersion = "1.0.0", Title = "title", Tags = "a b d", Summary = "summary", LicenseUrl = "http://www.tempuri.org/lic", ProjectUrl = "http://www.tempuri.org/proj", ReleaseNotes = "notes", Owners = "owners", Copyright = "copyright", RequireLicenseAcceptance = "true" }, Files = new List <TestNupkgFile>() { new TestNupkgFile("icon.png") } }; var testPackage2 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "2.0.0", Authors = "author2", Description = "desc2", IconUrl = "http://www.tempuri2.org/", Icon = "icon.png", Language = "en-us", MinClientVersion = "1.0.0", Title = "title2", Tags = "a b c", Summary = "summary2", LicenseUrl = "http://www.tempuri.org/lic2", ProjectUrl = "http://www.tempuri.org/proj2", ReleaseNotes = "notes2", Owners = "owners2", Copyright = "copyright2", RequireLicenseAcceptance = "true" }, Files = new List <TestNupkgFile>() { new TestNupkgFile("icon.png") } }; var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri); var sleetConfigPath = Path.Combine(target.Root, "sleet.config"); await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig); var zipFile = testPackage.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var settings = LocalSettings.Load(sleetConfigPath); var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, "local"); var success = await InitCommand.RunAsync(settings, fileSystem, log); // Act // Run sleet success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile2.FullName }, false, false, log); success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, false, false, log); // Create a repository abstraction for nuget var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri); var localSource = GetSource(outputRoot, baseUri, nugetFileSystem); var resource = await localSource.GetResourceAsync <PackageMetadataResource>(); var results = await resource.GetMetadataAsync("packageA", true, true, sourceCacheContext, log, CancellationToken.None); var resultArray = results.OrderBy(e => e.Identity.Version).ToArray(); // Assert Assert.True(success, log.ToString()); Assert.Equal(testPackage.Nuspec.Authors, resultArray[0].Authors); Assert.Equal(testPackage.Nuspec.Description, resultArray[0].Description); Assert.Null(resultArray[0].DownloadCount); Assert.Equal("https://localhost:8080/testFeed/flatcontainer/packagea/1.0.0/icon", resultArray[0].IconUrl.AbsoluteUri); Assert.Equal(testPackage.Nuspec.Id, resultArray[0].Identity.Id); Assert.Equal(testPackage.Nuspec.Version.ToString(), resultArray[0].Identity.Version.ToString()); Assert.Equal(testPackage.Nuspec.LicenseUrl, resultArray[0].LicenseUrl.AbsoluteUri); Assert.Null(resultArray[0].Owners); Assert.Equal(testPackage.Nuspec.ProjectUrl, resultArray[0].ProjectUrl.AbsoluteUri); Assert.Equal(testPackage.Nuspec.Summary, resultArray[0].Summary); Assert.Equal("a, b, d", resultArray[0].Tags); Assert.Equal(testPackage.Nuspec.Title, resultArray[0].Title); Assert.True(resultArray[0].Published.Value.Year == DateTime.UtcNow.Year); Assert.Equal("https://localhost:8080/testFeed/", resultArray[0].ReportAbuseUrl.AbsoluteUri); Assert.True(resultArray[0].RequireLicenseAcceptance); Assert.Equal(testPackage2.Nuspec.Authors, resultArray[1].Authors); Assert.Equal(testPackage2.Nuspec.Description, resultArray[1].Description); Assert.Null(resultArray[1].DownloadCount); Assert.Equal("https://localhost:8080/testFeed/flatcontainer/packagea/2.0.0/icon", resultArray[1].IconUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Id, resultArray[1].Identity.Id); Assert.Equal(testPackage2.Nuspec.Version.ToString(), resultArray[1].Identity.Version.ToString()); Assert.Equal(testPackage2.Nuspec.LicenseUrl, resultArray[1].LicenseUrl.AbsoluteUri); Assert.Null(resultArray[1].Owners); Assert.Equal(testPackage2.Nuspec.ProjectUrl, resultArray[1].ProjectUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Summary, resultArray[1].Summary); Assert.Equal("a, b, c", resultArray[1].Tags); Assert.Equal(testPackage2.Nuspec.Title, resultArray[1].Title); Assert.True(resultArray[1].Published.Value.Year == DateTime.UtcNow.Year); Assert.Equal("https://localhost:8080/testFeed/", resultArray[1].ReportAbuseUrl.AbsoluteUri); Assert.True(resultArray[1].RequireLicenseAcceptance); } }
public async Task GivenThatIRemoveAllPackagesWithTheCatalogDisabledVerifyItSucceeds() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; context.SourceSettings.CatalogEnabled = false; var testPackage1 = new TestNupkg("packageA", "1.0.1"); var testPackage2 = new TestNupkg("packageA", "1.0.2"); var testPackage3 = new TestNupkg("packageA", "1.0.3"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var zipFile3 = testPackage3.Save(packagesFolder.Root); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile3.FullName }, false, false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.3", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.1", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.2", "", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEmpty("all packages were removed"); indexPackages.Should().BeEmpty("all packages were removed"); searchPackages.Should().BeEmpty("all packages were removed"); autoCompletePackages.Should().BeEmpty("all packages were removed"); } }
public int Main(string[] args) { var app = new CommandLineApplication(); app.Name = "kpm"; var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue); app.HelpOption("-?|-h|--help"); app.VersionOption("--version", GetVersion()); // Show help information if no subcommand/option was specified app.OnExecute(() => { app.ShowHelp(); return(2); }); app.Command("restore", c => { c.Description = "Restore packages"; var argRoot = c.Argument("[root]", "Root of all projects to restore. It can be a directory, a project.json, or a global.json."); var optSource = c.Option("-s|--source <FEED>", "A list of packages sources to use for this command", CommandOptionType.MultipleValue); var optFallbackSource = c.Option("-f|--fallbacksource <FEED>", "A list of packages sources to use as a fallback", CommandOptionType.MultipleValue); var optProxy = c.Option("-p|--proxy <ADDRESS>", "The HTTP proxy to use when retrieving packages", CommandOptionType.SingleValue); var optNoCache = c.Option("--no-cache", "Do not use local cache", CommandOptionType.NoValue); var optPackageFolder = c.Option("--packages", "Path to restore packages", CommandOptionType.SingleValue); var optQuiet = c.Option("--quiet", "Do not show output such as HTTP request/cache information", CommandOptionType.NoValue); var optIgnoreFailedSources = c.Option("--ignore-failed-sources", "Ignore failed remote sources if there are local packages meeting version requirements", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(async() => { var command = new RestoreCommand(_environment); command.Reports = CreateReports(optionVerbose.HasValue(), optQuiet.HasValue()); command.RestoreDirectory = argRoot.Value; command.Sources = optSource.Values; command.FallbackSources = optFallbackSource.Values; command.NoCache = optNoCache.HasValue(); command.PackageFolder = optPackageFolder.Value(); command.IgnoreFailedSources = optIgnoreFailedSources.HasValue(); if (optProxy.HasValue()) { Environment.SetEnvironmentVariable("http_proxy", optProxy.Value()); } var success = await command.ExecuteCommand(); return(success ? 0 : 1); }); }); app.Command("bundle", c => { c.Description = "Bundle application for deployment"; var argProject = c.Argument("[project]", "Path to project, default is current directory"); var optionOut = c.Option("-o|--out <PATH>", "Where does it go", CommandOptionType.SingleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "The configuration to use for deployment (Debug|Release|{Custom})", CommandOptionType.SingleValue); var optionOverwrite = c.Option("--overwrite", "Remove existing files in target folders", CommandOptionType.NoValue); var optionNoSource = c.Option("--no-source", "Compiles the source files into NuGet packages", CommandOptionType.NoValue); var optionRuntime = c.Option("--runtime <RUNTIME>", "Name or full path of the runtime folder to include", CommandOptionType.MultipleValue); var optionNative = c.Option("--native", "Build and include native images. User must provide targeted CoreCLR runtime versions along with this option.", CommandOptionType.NoValue); var optionWwwRoot = c.Option("--wwwroot <NAME>", "Name of public folder in the project directory", CommandOptionType.SingleValue); var optionWwwRootOut = c.Option("--wwwroot-out <NAME>", "Name of public folder in the bundle, can be used only when the '--wwwroot' option or 'webroot' in project.json is specified", CommandOptionType.SingleValue); var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of bundled files", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var options = new BundleOptions { OutputDir = optionOut.Value(), ProjectDir = argProject.Value ?? System.IO.Directory.GetCurrentDirectory(), Configuration = optionConfiguration.Value() ?? "Debug", RuntimeTargetFramework = _environment.RuntimeFramework, WwwRoot = optionWwwRoot.Value(), WwwRootOut = optionWwwRootOut.Value() ?? optionWwwRoot.Value(), Overwrite = optionOverwrite.HasValue(), NoSource = optionNoSource.HasValue(), Runtimes = optionRuntime.HasValue() ? string.Join(";", optionRuntime.Values). Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) : new string[0], Native = optionNative.HasValue(), Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()) }; var manager = new BundleManager(_hostServices, options); if (!manager.Bundle()) { return(-1); } return(0); }); }); app.Command("pack", c => { c.Description = "Build NuGet packages for the project in given directory"; var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue); var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue); var optionDependencies = c.Option("--dependencies", "Copy dependencies", CommandOptionType.NoValue); var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of nupkgs", CommandOptionType.NoValue); var argProjectDir = c.Argument("[project]", "Project to pack, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var buildOptions = new BuildOptions(); buildOptions.OutputDir = optionOut.Value(); buildOptions.ProjectDir = argProjectDir.Value ?? Directory.GetCurrentDirectory(); buildOptions.Configurations = optionConfiguration.Values; buildOptions.TargetFrameworks = optionFramework.Values; buildOptions.GeneratePackages = true; buildOptions.Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()); var projectManager = new BuildManager(_hostServices, buildOptions); if (!projectManager.Build()) { return(-1); } return(0); }); }); app.Command("build", c => { c.Description = "Produce assemblies for the project in given directory"; var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue); var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue); var optionQuiet = c.Option("--quiet", "Do not show output such as dependencies in use", CommandOptionType.NoValue); var argProjectDir = c.Argument("[project]", "Project to build, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var buildOptions = new BuildOptions(); buildOptions.OutputDir = optionOut.Value(); buildOptions.ProjectDir = argProjectDir.Value ?? Directory.GetCurrentDirectory(); buildOptions.Configurations = optionConfiguration.Values; buildOptions.TargetFrameworks = optionFramework.Values; buildOptions.GeneratePackages = false; buildOptions.Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()); var projectManager = new BuildManager(_hostServices, buildOptions); if (!projectManager.Build()) { return(-1); } return(0); }); }); app.Command("add", c => { c.Description = "Add a dependency into dependencies section of project.json"; var argName = c.Argument("[name]", "Name of the dependency to add"); var argVersion = c.Argument("[version]", "Version of the dependency to add"); var argProject = c.Argument("[project]", "Path to project, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); var command = new AddCommand(); command.Reports = reports; command.Name = argName.Value; command.Version = argVersion.Value; command.ProjectDir = argProject.Value; var success = command.ExecuteCommand(); return(success ? 0 : 1); }); }); app.Command("install", c => { c.Description = "Install the given dependency"; var argName = c.Argument("[name]", "Name of the dependency to add"); var argVersion = c.Argument("[version]", "Version of the dependency to add, default is the latest version."); var argProject = c.Argument("[project]", "Path to project, default is current directory"); var optSource = c.Option("-s|--source <FEED>", "A list of packages sources to use for this command", CommandOptionType.MultipleValue); var optFallbackSource = c.Option("-f|--fallbacksource <FEED>", "A list of packages sources to use as a fallback", CommandOptionType.MultipleValue); var optProxy = c.Option("-p|--proxy <ADDRESS>", "The HTTP proxy to use when retrieving packages", CommandOptionType.SingleValue); var optNoCache = c.Option("--no-cache", "Do not use local cache", CommandOptionType.NoValue); var optPackageFolder = c.Option("--packages", "Path to restore packages", CommandOptionType.SingleValue); var optQuiet = c.Option("--quiet", "Do not show output such as HTTP request/cache information", CommandOptionType.NoValue); var optIgnoreFailedSources = c.Option("--ignore-failed-sources", "Ignore failed remote sources if there are local packages meeting version requirements", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(async() => { var reports = CreateReports(optionVerbose.HasValue(), optQuiet.HasValue()); var addCmd = new AddCommand(); addCmd.Reports = reports; addCmd.Name = argName.Value; addCmd.Version = argVersion.Value; addCmd.ProjectDir = argProject.Value; var restoreCmd = new RestoreCommand(_environment); restoreCmd.Reports = reports; restoreCmd.RestoreDirectory = argProject.Value; restoreCmd.Sources = optSource.Values; restoreCmd.FallbackSources = optFallbackSource.Values; restoreCmd.NoCache = optNoCache.HasValue(); restoreCmd.PackageFolder = optPackageFolder.Value(); restoreCmd.IgnoreFailedSources = optIgnoreFailedSources.HasValue(); if (optProxy.HasValue()) { Environment.SetEnvironmentVariable("http_proxy", optProxy.Value()); } var installCmd = new InstallCommand(addCmd, restoreCmd); installCmd.Reports = reports; var success = await installCmd.ExecuteCommand(); return(success ? 0 : 1); }); }); app.Command("packages", packagesCommand => { packagesCommand.Description = "Commands related to managing local and remote packages folders"; packagesCommand.HelpOption("-?|-h|--help"); packagesCommand.OnExecute(() => { packagesCommand.ShowHelp(); return(2); }); packagesCommand.Command("add", c => { c.Description = "Add a NuGet package to the specified packages folder"; var argNupkg = c.Argument("[nupkg]", "Path to a NuGet package"); var argSource = c.Argument("[source]", "Path to packages folder"); c.HelpOption("-?|-h|--help"); c.OnExecute(async() => { var options = new AddOptions { Reports = CreateReports(optionVerbose.HasValue(), quiet: false), SourcePackages = argSource.Value, NuGetPackage = argNupkg.Value }; var command = new Packages.AddCommand(options); var success = await command.Execute(); return(success ? 0 : 1); }); }); packagesCommand.Command("push", c => { c.Description = "Incremental copy of files from local packages to remote location"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); // Implicitly commit changes before push var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); var success = commitCommand.Execute(); if (!success) { return(1); } var pushOptions = new PushOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pushCommand = new PushCommand(pushOptions); success = pushCommand.Execute(); return(success ? 0 : 1); }); }); packagesCommand.Command("pull", c => { c.Description = "Incremental copy of files from remote location to local packages"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); bool success; if (Directory.Exists(argSource.Value)) { // Implicitly commit changes before pull var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); success = commitCommand.Execute(); if (!success) { return(1); } } var pullOptions = new PullOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pullCommand = new PullCommand(pullOptions); success = pullCommand.Execute(); return(success ? 0 : 1); }); }); }); app.Command("list", c => { c.Description = "Print the dependencies of a given project."; var showAssemblies = c.Option("-a|--assemblies", "Show the assembly files that are depended on by given project.", CommandOptionType.NoValue); var framework = c.Option("--framework", "Show dependencies for only the given framework.", CommandOptionType.SingleValue); var runtimeFolder = c.Option("--runtime", "The folder containing all available framework assemblies.", CommandOptionType.SingleValue); var argProject = c.Argument("[project]", "The path to project. If omitted, the command will use the project in the current directory."); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var options = new DependencyListOptions(CreateReports(verbose: true, quiet: false), argProject, framework) { ShowAssemblies = showAssemblies.HasValue(), RuntimeFolder = runtimeFolder.Value(), }; if (!options.Valid) { if (options.Project == null) { options.Reports.Error.WriteLine(string.Format("A project could not be found in {0}.", options.Path).Red()); return(1); } else { options.Reports.Error.WriteLine("Invalid options.".Red()); return(2); } } var command = new DependencyListCommand(options); return(command.Execute()); }); }); // "kpm wrap" invokes MSBuild, which is not available on *nix if (!PlatformHelper.IsMono) { app.Command("wrap", c => { c.Description = "Wrap a csproj into a project.json, which can be referenced by project.json files"; var argPath = c.Argument("[path]", "Path to csproj to be wrapped"); var optConfiguration = c.Option("--configuration <CONFIGURATION>", "Configuration of wrapped project, default is 'debug'", CommandOptionType.SingleValue); var optMsBuildPath = c.Option("--msbuild <PATH>", @"Path to MSBuild, default is '%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe'", CommandOptionType.SingleValue); var optInPlace = c.Option("-i|--in-place", "Generate or update project.json files in project directories of csprojs", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); var command = new WrapCommand(); command.Reports = reports; command.CsProjectPath = argPath.Value; command.Configuration = optConfiguration.Value(); command.MsBuildPath = optMsBuildPath.Value(); command.InPlace = optInPlace.HasValue(); var success = command.ExecuteCommand(); return(success ? 0 : 1); }); }); } return(app.Execute(args)); }
public async Task AddRemove_AddManyPackagesThenRemoveSome() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>(); var ids = new[] { "a", "b", "c", "d" }; foreach (var id in ids) { for (var i = 0; i < 50; i++) { var testPackage = new TestNupkg(id, $"{i}.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); identities.Add(new PackageIdentity(testPackage.Nuspec.Id, NuGetVersion.Parse(testPackage.Nuspec.Version))); } } var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); // Act // run delete command await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "b", null, "removing", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogPackages = await catalog.GetPackagesAsync(); var regPackages = new HashSet <PackageIdentity>(); foreach (var id in ids) { regPackages.UnionWith(await registration.GetPackagesByIdAsync(id)); } var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(identities.Count + 50, catalogEntries.Count); Assert.Equal(identities.Count - 50, catalogExistingEntries.Count); regPackages.Count.Should().Be(identities.Count - 50); Assert.Equal(identities.Count - 50, indexPackages.Count); Assert.Equal(identities.Count - 50, searchPackages.Count); Assert.Equal(ids.Length - 1, autoCompletePackages.Count); } }
public async Task PushCommand_GivenADifferentNuspecCasingVerifyPush() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var tempZip = new ZipArchive(zipFile.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None), ZipArchiveMode.Update)) { var nuspec = tempZip.Entries.Single(e => e.FullName == "packageA.nuspec"); using (var ms = new MemoryStream()) { using (var nuspecStream = nuspec.Open()) { nuspecStream.CopyTo(ms); } ms.Position = 0; nuspec.Delete(); var newEntry = tempZip.CreateEntry("PacKAGEa.NuSpec"); ms.CopyTo(newEntry.Open()); } } using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, indexPackages.Count); } } }
public async Task RetentionPruneCommand_PrunesOnPushWithMultiplePushes() { // Arrange using (var packagesFolder = new TestFolder()) using (var packagesFolder2 = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true, RetentionMaxStableVersions = 2, RetentionMaxPrereleaseVersions = 1 } }; // Initial packages var identities = new List <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("1.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("1.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("1.0.0")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0")), }; await InitCommand.InitAsync(context); // Push packages 1 at a time foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); } // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert indexPackages.Count().Should().Be(6); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("3.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("2.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("3.0.0-beta"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("3.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("2.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("3.0.0-beta"))).Should().BeTrue(); } }
public async Task Symbols_ForcePushPackageShouldNotAffectOtherType(bool isSymbols) { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; // Create package var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); var symPkgA = new TestNupkg("a", "1.0.0"); symPkgA.Files.Clear(); symPkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); symPkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); symPkgA.Nuspec.IsSymbolPackage = true; var symZip = symPkgA.Save(testContext.Packages); var symPkgInput = testContext.GetPackageInput(symZip); var forcePushZip = zip.FullName; if (isSymbols) { forcePushZip = symZip.FullName; } // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName, symZip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Force push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { forcePushZip }, force : true, skipExisting : false, log : testContext.SleetContext.Log); // Validate success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); success.Should().BeTrue(); // Both packages should exist, force should not delete one or the other. var index = new PackageIndex(context); (await index.Exists(identity)).Should().BeTrue(); (await index.SymbolsExists(identity)).Should().BeTrue(); } }
public void PushCommandUsesNuGetOrgWhenNoSourceSpecified(string input, string expected) { var push = new PushCommand(CreateSourceProvider(), CreateSettings()); Assert.Equal(expected, push.ResolveSource(input)); }
public async Task Symbols_AddSymbolsPackagesContainingTheSameFilesVerifyDeleteDoesNotRemove() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; // Create package var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); pkgA.Nuspec.IsSymbolPackage = true; var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); var identityB = new PackageIdentity("b", NuGetVersion.Parse("1.0.0")); var pkgB = new TestNupkg("b", "1.0.0"); pkgB.Files.Clear(); pkgB.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgB.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); pkgB.Nuspec.IsSymbolPackage = true; var zipB = pkgB.Save(testContext.Packages); var pkgInputB = testContext.GetPackageInput(zipB); // File path var dllPath = Path.Combine(testContext.Target, "symbols", "a.dll", "A7F83EF08000", "a.dll"); var dllPackagesJsonPath = Path.Combine(testContext.Target, "symbols", "a.dll", "A7F83EF08000", "packages.json"); var pdbPath = Path.Combine(testContext.Target, "symbols", "a.pdb", "B1680B8315F8485EA0A10F55AF08B565ffffffff", "a.pdb"); var pdbPackagesJsonPath = Path.Combine(testContext.Target, "symbols", "a.pdb", "B1680B8315F8485EA0A10F55AF08B565ffffffff", "packages.json"); var files = new List <string> { dllPath, dllPackagesJsonPath, pdbPath, pdbPackagesJsonPath }; // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName, zipB.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Verify files are present files.ForEach(e => File.Exists(e).Should().BeTrue(e)); // Remove success &= await DeleteCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, "a", "1.0.0", "reason", force : false, log : testContext.SleetContext.Log); // Verify files are still present files.ForEach(e => File.Exists(e).Should().BeTrue(e)); // Validate success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); success.Should().BeTrue(); } }
public async Task Symbols_AddAndRemovePackagesMultipleTimesVerifyValidation() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; // Create package var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); var symPkgA = new TestNupkg("a", "1.0.0"); symPkgA.Files.Clear(); symPkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); symPkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); symPkgA.Nuspec.IsSymbolPackage = true; var symZip = symPkgA.Save(testContext.Packages); var symPkgInput = testContext.GetPackageInput(symZip); // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName, symZip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Validate 1 success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); // Remove success &= await DeleteCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, "a", "1.0.0", "reason", force : false, log : testContext.SleetContext.Log); // Validate 2 success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); // Push Again success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName, symZip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Validate 3 success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); // Remove Again success &= await DeleteCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, "a", "1.0.0", "reason", force : false, log : testContext.SleetContext.Log); // Validate 4 success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); success.Should().BeTrue(); } }
public async Task Symbols_RemovePackageVerifySymbolsRemoved() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; // Create package var identity = new PackageIdentity("a", NuGetVersion.Parse("1.0.0")); var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); pkgA.Nuspec.IsSymbolPackage = true; var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); // File path var nupkgPath = Path.Combine(testContext.Target, ToLocalPath(SymbolsIndexUtility.GetSymbolsNupkgPath(identity))); var detailsPath = Path.Combine(testContext.Target, ToLocalPath(SymbolsIndexUtility.GetSymbolsPackageDetailsPath(identity))); var dllPath = Path.Combine(testContext.Target, "symbols", "a.dll", "A7F83EF08000", "a.dll"); var dllPackagesJsonPath = Path.Combine(testContext.Target, "symbols", "a.dll", "A7F83EF08000", "packages.json"); var pdbPath = Path.Combine(testContext.Target, "symbols", "a.pdb", "B1680B8315F8485EA0A10F55AF08B565ffffffff", "a.pdb"); var pdbPackagesJsonPath = Path.Combine(testContext.Target, "symbols", "a.pdb", "B1680B8315F8485EA0A10F55AF08B565ffffffff", "packages.json"); var packageAssetsPath = Path.Combine(testContext.Target, ToLocalPath(SymbolsIndexUtility.GetPackageToAssemblyIndexPath(identity))); var files = new List <string> { nupkgPath, detailsPath, dllPath, dllPackagesJsonPath, pdbPath, pdbPackagesJsonPath, packageAssetsPath }; // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Verify files are present files.ForEach(e => File.Exists(e).Should().BeTrue(e)); // Remove success &= await DeleteCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, "a", "1.0.0", "reason", force : false, log : testContext.SleetContext.Log); // Verify files are gone files.ForEach(e => File.Exists(e).Should().BeFalse(e)); // Validate success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, log : testContext.SleetContext.Log); success.Should().BeTrue(); var testLogger = (TestLogger)testContext.SleetContext.Log; testLogger.GetMessages().Should().Contain("Removing symbols package a.1.0.0"); } }
public async Task Symbols_AddSymbolsPackageVerifyFeed() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var symbols = new Symbols(context); var packageIndex = new PackageIndex(context); var catalog = new Catalog(context); var autoComplete = new AutoComplete(context); var flatContainer = new FlatContainer(context); var registrations = new Registrations(context); var search = new Search(context); // Create package var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); pkgA.Nuspec.IsSymbolPackage = true; var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Validate success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, testContext.SleetContext.Log); success.Should().BeTrue(); // Exists under symbols (await symbols.GetSymbolsPackagesAsync()).Should().NotBeEmpty(); (await packageIndex.GetSymbolsPackagesAsync()).Should().NotBeEmpty(); // Does not exist in non-symbols (await symbols.GetPackagesAsync()).Should().BeEmpty(); (await packageIndex.GetPackagesAsync()).Should().BeEmpty(); // Verify it does not appear in other services (await catalog.GetPackagesAsync()).Should().BeEmpty(); (await autoComplete.GetPackageIds()).Should().BeEmpty(); (await flatContainer.GetPackagesByIdAsync("a")).Should().BeEmpty(); (await registrations.GetPackagesByIdAsync("a")).Should().BeEmpty(); (await search.GetPackagesAsync()).Should().BeEmpty(); // Verify nupkg exists var nupkgPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "a.1.0.0.symbols.nupkg"); File.Exists(nupkgPath).Should().BeTrue(); // Verify package details var detailsPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "package.json"); File.Exists(detailsPath).Should().BeTrue(); } }
public async Task Symbols_AddPackageWithSymbolsVerifyInIndex(string isSymbolsString) { var isSymbols = bool.Parse(isSymbolsString); using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var symbols = new Symbols(context); var packageIndex = new PackageIndex(context); // Create package var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); pkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); pkgA.Nuspec.IsSymbolPackage = isSymbols; var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Validate success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, testContext.SleetContext.Log); var symbolsIndex = new HashSet <PackageIdentity>(); var packageIndexPkgs = new HashSet <PackageIdentity>(); if (isSymbols) { symbolsIndex.UnionWith(await symbols.GetSymbolsPackagesAsync()); packageIndexPkgs.UnionWith(await packageIndex.GetSymbolsPackagesAsync()); } else { symbolsIndex.UnionWith(await symbols.GetPackagesAsync()); packageIndexPkgs.UnionWith(await packageIndex.GetPackagesAsync()); } // Verify package does not show up in symbols index symbolsIndex.Should().BeEquivalentTo(new[] { new PackageIdentity("a", NuGetVersion.Parse("1.0.0")) }); packageIndexPkgs.Should().BeEquivalentTo(new[] { new PackageIdentity("a", NuGetVersion.Parse("1.0.0")) }); // Validate success.Should().BeTrue(); } }
public async Task SubFeed_PushAndVerifyWithNestedFeedsVerifySuccess() { using (var packagesFolder = new TestFolder()) using (var testContext = new AzureTestContext()) using (var testContext2 = new AzureTestContext()) { // Use a subfeed for the filesystem var subFeedName = "testSubFeed"; var root = UriUtility.GetPath(testContext.Uri, subFeedName); testContext.FileSystem = new AzureFileSystem(testContext.LocalCache, root, root, testContext.StorageAccount, testContext.ContainerName, feedSubPath: subFeedName); await testContext.InitAsync(); await testContext2.InitAsync(); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); var result = await InitCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, enableCatalog : true, enableSymbols : true, log : testContext.Logger, token : CancellationToken.None); result &= await InitCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, enableCatalog : true, enableSymbols : true, log : testContext2.Logger, token : CancellationToken.None); result &= await PushCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext.Logger); result &= await PushCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext2.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, testContext.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, testContext2.Logger); result.Should().BeTrue(); await testContext.CleanupAsync(); await testContext2.CleanupAsync(); } }
private async Task <bool> PushAsync( IEnumerable <string> items, PushOptions options) { LocalSettings settings = GetSettings(); AzureFileSystem fileSystem = GetAzureFileSystem(); SleetLogger log = new SleetLogger(Log); var packagesToPush = items.ToList(); if (!options.AllowOverwrite && options.PassIfExistingItemIdentical) { var context = new SleetContext { LocalSettings = settings, Log = log, Source = fileSystem, Token = CancellationToken }; context.SourceSettings = await FeedSettingsUtility.GetSettingsOrDefault( context.Source, context.Log, context.Token); var flatContainer = new FlatContainer(context); var packageIndex = new PackageIndex(context); // Check packages sequentially: Task.WhenAll caused IO exceptions in Sleet. for (int i = packagesToPush.Count - 1; i >= 0; i--) { string item = packagesToPush[i]; bool?identical = await IsPackageIdenticalOnFeedAsync( item, packageIndex, context.Source, flatContainer, log); if (identical == null) { continue; } packagesToPush.RemoveAt(i); if (identical == true) { Log.LogMessage( MessageImportance.Normal, "Package exists on the feed, and is verified to be identical. " + $"Skipping upload: '{item}'"); } else { Log.LogError( "Package exists on the feed, but contents are different. " + $"Upload failed: '{item}'"); } } if (!packagesToPush.Any()) { Log.LogMessage("After skipping idempotent uploads, no items need pushing."); return(true); } } return(await PushCommand.RunAsync( settings, fileSystem, packagesToPush, options.AllowOverwrite, skipExisting : false, log : log)); }
private static void RegisterPushSubcommand(CommandLineApplication packagesCmd, ReportsFactory reportsFactory) { packagesCmd.Command("push", c => { c.Description = "Incremental copy of files from local packages to remote location"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { c.ShowRootCommandFullNameAndVersion(); var reports = reportsFactory.CreateReports(quiet: false); // Implicitly commit changes before push var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); var success = commitCommand.Execute(); if (!success) { return 1; } var pushOptions = new PushOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pushCommand = new PushCommand(pushOptions); success = pushCommand.Execute(); return success ? 0 : 1; }); }); }
public async Task NuGetReader_PackageSearchResourceAsync() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var outputRoot = Path.Combine(target.Root, "output"); var baseUri = UriUtility.CreateUri("https://localhost:8080/testFeed/"); var log = new TestLogger(); var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0", Authors = "author", Description = "desc", IconUrl = "http://www.tempuri.org", Language = "en-us", MinClientVersion = "1.0.0", Title = "title", Tags = "a b d", Summary = "summary", LicenseUrl = "http://www.tempuri.org/lic", ProjectUrl = "http://www.tempuri.org/proj", ReleaseNotes = "notes", Owners = "owners", Copyright = "copyright", RequireLicenseAcceptance = "true" } }; var testPackage2 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "2.0.0", Authors = "author2", Description = "desc2", IconUrl = "http://www.tempuri2.org/", Language = "en-us", MinClientVersion = "1.0.0", Title = "title2", Tags = "a b c", Summary = "summary2", LicenseUrl = "http://www.tempuri.org/lic2", ProjectUrl = "http://www.tempuri.org/proj2", ReleaseNotes = "notes2", Owners = "owners2", Copyright = "copyright2", RequireLicenseAcceptance = "true" } }; var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri); var sleetConfigPath = Path.Combine(target.Root, "sleet.config"); await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig); var zipFile = testPackage.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var settings = LocalSettings.Load(sleetConfigPath); var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, "local"); var success = await InitCommand.RunAsync(settings, fileSystem, log); // Act // Run sleet success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile2.FullName }, false, false, log); success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, false, false, log); // Create a repository abstraction for nuget var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri); var localSource = GetSource(outputRoot, baseUri, nugetFileSystem); var resource = await localSource.GetResourceAsync <PackageSearchResource>(); var results = await resource.SearchAsync(string.Empty, new SearchFilter(includePrerelease : true), 0, 10, log, CancellationToken.None); var result = results.Single(); var versions = await result.GetVersionsAsync(); // Assert Assert.True(success, log.ToString()); Assert.Equal(testPackage2.Nuspec.Authors, result.Authors); Assert.Equal(testPackage2.Nuspec.Description, result.Description); Assert.Equal(0, result.DownloadCount); Assert.Equal(testPackage2.Nuspec.IconUrl, result.IconUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Id, result.Identity.Id); Assert.Equal(testPackage2.Nuspec.Version.ToString(), result.Identity.Version.ToString()); Assert.Equal(testPackage2.Nuspec.LicenseUrl, result.LicenseUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Owners, result.Owners); Assert.Equal(testPackage2.Nuspec.ProjectUrl, result.ProjectUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Summary, result.Summary); Assert.Equal("a, b, c", result.Tags); Assert.Equal(testPackage2.Nuspec.Title, result.Title); Assert.Equal(2, versions.Count()); Assert.Equal("1.0.0", versions.First().Version.ToString()); Assert.Equal("2.0.0", versions.Skip(1).First().Version.ToString()); } }
public int Main(string[] args) { var app = new CommandLineApplication(); app.Name = "kpm"; var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue); app.HelpOption("-?|-h|--help"); app.VersionOption("--version", GetVersion()); // Show help information if no subcommand/option was specified app.OnExecute(() => { app.ShowHelp(); return 2; }); app.Command("restore", c => { c.Description = "Restore packages"; var argRoot = c.Argument("[root]", "Root of all projects to restore. It can be a directory, a project.json, or a global.json."); var optSource = c.Option("-s|--source <FEED>", "A list of packages sources to use for this command", CommandOptionType.MultipleValue); var optFallbackSource = c.Option("-f|--fallbacksource <FEED>", "A list of packages sources to use as a fallback", CommandOptionType.MultipleValue); var optProxy = c.Option("-p|--proxy <ADDRESS>", "The HTTP proxy to use when retrieving packages", CommandOptionType.SingleValue); var optNoCache = c.Option("--no-cache", "Do not use local cache", CommandOptionType.NoValue); var optPackageFolder = c.Option("--packages", "Path to restore packages", CommandOptionType.SingleValue); var optQuiet = c.Option("--quiet", "Do not show output such as HTTP request/cache information", CommandOptionType.NoValue); var optIgnoreFailedSources = c.Option("--ignore-failed-sources", "Ignore failed remote sources if there are local packages meeting version requirements", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var command = new RestoreCommand(_environment); command.Reports = CreateReports(optionVerbose.HasValue(), optQuiet.HasValue()); command.RestoreDirectory = argRoot.Value; command.Sources = optSource.Values; command.FallbackSources = optFallbackSource.Values; command.NoCache = optNoCache.HasValue(); command.PackageFolder = optPackageFolder.Value(); command.IgnoreFailedSources = optIgnoreFailedSources.HasValue(); if (optProxy.HasValue()) { Environment.SetEnvironmentVariable("http_proxy", optProxy.Value()); } var success = await command.ExecuteCommand(); return success ? 0 : 1; }); }); app.Command("bundle", c => { c.Description = "Bundle application for deployment"; var argProject = c.Argument("[project]", "Path to project, default is current directory"); var optionOut = c.Option("-o|--out <PATH>", "Where does it go", CommandOptionType.SingleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "The configuration to use for deployment (Debug|Release|{Custom})", CommandOptionType.SingleValue); var optionOverwrite = c.Option("--overwrite", "Remove existing files in target folders", CommandOptionType.NoValue); var optionNoSource = c.Option("--no-source", "Compiles the source files into NuGet packages", CommandOptionType.NoValue); var optionRuntime = c.Option("--runtime <RUNTIME>", "Name or full path of the runtime folder to include", CommandOptionType.MultipleValue); var optionNative = c.Option("--native", "Build and include native images. User must provide targeted CoreCLR runtime versions along with this option.", CommandOptionType.NoValue); var optionWwwRoot = c.Option("--wwwroot <NAME>", "Name of public folder in the project directory", CommandOptionType.SingleValue); var optionWwwRootOut = c.Option("--wwwroot-out <NAME>", "Name of public folder in the bundle, can be used only when the '--wwwroot' option or 'webroot' in project.json is specified", CommandOptionType.SingleValue); var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of bundled files", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var options = new BundleOptions { OutputDir = optionOut.Value(), ProjectDir = argProject.Value ?? System.IO.Directory.GetCurrentDirectory(), Configuration = optionConfiguration.Value() ?? "Debug", RuntimeTargetFramework = _environment.RuntimeFramework, WwwRoot = optionWwwRoot.Value(), WwwRootOut = optionWwwRootOut.Value() ?? optionWwwRoot.Value(), Overwrite = optionOverwrite.HasValue(), NoSource = optionNoSource.HasValue(), Runtimes = optionRuntime.HasValue() ? string.Join(";", optionRuntime.Values). Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) : new string[0], Native = optionNative.HasValue(), Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()) }; var manager = new BundleManager(_hostServices, options); if (!manager.Bundle()) { return -1; } return 0; }); }); app.Command("pack", c => { c.Description = "Build NuGet packages for the project in given directory"; var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue); var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue); var optionDependencies = c.Option("--dependencies", "Copy dependencies", CommandOptionType.NoValue); var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of nupkgs", CommandOptionType.NoValue); var argProjectDir = c.Argument("[project]", "Project to pack, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var buildOptions = new BuildOptions(); buildOptions.OutputDir = optionOut.Value(); buildOptions.ProjectDir = argProjectDir.Value ?? Directory.GetCurrentDirectory(); buildOptions.Configurations = optionConfiguration.Values; buildOptions.TargetFrameworks = optionFramework.Values; buildOptions.GeneratePackages = true; buildOptions.Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()); var projectManager = new BuildManager(_hostServices, buildOptions); if (!projectManager.Build()) { return -1; } return 0; }); }); app.Command("build", c => { c.Description = "Produce assemblies for the project in given directory"; var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue); var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue); var optionQuiet = c.Option("--quiet", "Do not show output such as dependencies in use", CommandOptionType.NoValue); var argProjectDir = c.Argument("[project]", "Project to build, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var buildOptions = new BuildOptions(); buildOptions.OutputDir = optionOut.Value(); buildOptions.ProjectDir = argProjectDir.Value ?? Directory.GetCurrentDirectory(); buildOptions.Configurations = optionConfiguration.Values; buildOptions.TargetFrameworks = optionFramework.Values; buildOptions.GeneratePackages = false; buildOptions.Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()); var projectManager = new BuildManager(_hostServices, buildOptions); if (!projectManager.Build()) { return -1; } return 0; }); }); app.Command("add", c => { c.Description = "Add a dependency into dependencies section of project.json"; var argName = c.Argument("[name]", "Name of the dependency to add"); var argVersion = c.Argument("[version]", "Version of the dependency to add"); var argProject = c.Argument("[project]", "Path to project, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); var command = new AddCommand(); command.Reports = reports; command.Name = argName.Value; command.Version = argVersion.Value; command.ProjectDir = argProject.Value; var success = command.ExecuteCommand(); return success ? 0 : 1; }); }); app.Command("install", c => { c.Description = "Install the given dependency"; var argName = c.Argument("[name]", "Name of the dependency to add"); var argVersion = c.Argument("[version]", "Version of the dependency to add, default is the latest version."); var argProject = c.Argument("[project]", "Path to project, default is current directory"); var optSource = c.Option("-s|--source <FEED>", "A list of packages sources to use for this command", CommandOptionType.MultipleValue); var optFallbackSource = c.Option("-f|--fallbacksource <FEED>", "A list of packages sources to use as a fallback", CommandOptionType.MultipleValue); var optProxy = c.Option("-p|--proxy <ADDRESS>", "The HTTP proxy to use when retrieving packages", CommandOptionType.SingleValue); var optNoCache = c.Option("--no-cache", "Do not use local cache", CommandOptionType.NoValue); var optPackageFolder = c.Option("--packages", "Path to restore packages", CommandOptionType.SingleValue); var optQuiet = c.Option("--quiet", "Do not show output such as HTTP request/cache information", CommandOptionType.NoValue); var optIgnoreFailedSources = c.Option("--ignore-failed-sources", "Ignore failed remote sources if there are local packages meeting version requirements", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var reports = CreateReports(optionVerbose.HasValue(), optQuiet.HasValue()); var addCmd = new AddCommand(); addCmd.Reports = reports; addCmd.Name = argName.Value; addCmd.Version = argVersion.Value; addCmd.ProjectDir = argProject.Value; var restoreCmd = new RestoreCommand(_environment); restoreCmd.Reports = reports; restoreCmd.RestoreDirectory = argProject.Value; restoreCmd.Sources = optSource.Values; restoreCmd.FallbackSources = optFallbackSource.Values; restoreCmd.NoCache = optNoCache.HasValue(); restoreCmd.PackageFolder = optPackageFolder.Value(); restoreCmd.IgnoreFailedSources = optIgnoreFailedSources.HasValue(); if (optProxy.HasValue()) { Environment.SetEnvironmentVariable("http_proxy", optProxy.Value()); } var installCmd = new InstallCommand(addCmd, restoreCmd); installCmd.Reports = reports; var success = await installCmd.ExecuteCommand(); return success ? 0 : 1; }); }); app.Command("packages", packagesCommand => { packagesCommand.Description = "Commands related to managing local and remote packages folders"; packagesCommand.HelpOption("-?|-h|--help"); packagesCommand.OnExecute(() => { packagesCommand.ShowHelp(); return 2; }); packagesCommand.Command("add", c => { c.Description = "Add a NuGet package to the specified packages folder"; var argNupkg = c.Argument("[nupkg]", "Path to a NuGet package"); var argSource = c.Argument("[source]", "Path to packages folder"); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var options = new AddOptions { Reports = CreateReports(optionVerbose.HasValue(), quiet: false), SourcePackages = argSource.Value, NuGetPackage = argNupkg.Value }; var command = new Packages.AddCommand(options); var success = await command.Execute(); return success ? 0 : 1; }); }); packagesCommand.Command("push", c => { c.Description = "Incremental copy of files from local packages to remote location"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); // Implicitly commit changes before push var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); var success = commitCommand.Execute(); if (!success) { return 1; } var pushOptions = new PushOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pushCommand = new PushCommand(pushOptions); success = pushCommand.Execute(); return success ? 0 : 1; }); }); packagesCommand.Command("pull", c => { c.Description = "Incremental copy of files from remote location to local packages"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); bool success; if (Directory.Exists(argSource.Value)) { // Implicitly commit changes before pull var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); success = commitCommand.Execute(); if (!success) { return 1; } } var pullOptions = new PullOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pullCommand = new PullCommand(pullOptions); success = pullCommand.Execute(); return success ? 0 : 1; }); }); }); app.Command("list", c => { c.Description = "Print the dependencies of a given project."; var showAssemblies = c.Option("-a|--assemblies", "Show the assembly files that are depended on by given project.", CommandOptionType.NoValue); var framework = c.Option("--framework", "Show dependencies for only the given framework.", CommandOptionType.SingleValue); var runtimeFolder = c.Option("--runtime", "The folder containing all available framework assemblies.", CommandOptionType.SingleValue); var argProject = c.Argument("[project]", "The path to project. If omitted, the command will use the project in the current directory."); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var options = new DependencyListOptions(CreateReports(verbose: true, quiet: false), argProject, framework) { ShowAssemblies = showAssemblies.HasValue(), RuntimeFolder = runtimeFolder.Value(), }; if (!options.Valid) { if (options.Project == null) { options.Reports.Error.WriteLine(string.Format("A project could not be found in {0}.", options.Path).Red()); return 1; } else { options.Reports.Error.WriteLine("Invalid options.".Red()); return 2; } } var command = new DependencyListCommand(options); return command.Execute(); }); }); // "kpm wrap" invokes MSBuild, which is not available on *nix if (!PlatformHelper.IsMono) { app.Command("wrap", c => { c.Description = "Wrap a csproj into a project.json, which can be referenced by project.json files"; var argPath = c.Argument("[path]", "Path to csproj to be wrapped"); var optConfiguration = c.Option("--configuration <CONFIGURATION>", "Configuration of wrapped project, default is 'debug'", CommandOptionType.SingleValue); var optMsBuildPath = c.Option("--msbuild <PATH>", @"Path to MSBuild, default is '%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe'", CommandOptionType.SingleValue); var optInPlace = c.Option("-i|--in-place", "Generate or update project.json files in project directories of csprojs", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); var command = new WrapCommand(); command.Reports = reports; command.CsProjectPath = argPath.Value; command.Configuration = optConfiguration.Value(); command.MsBuildPath = optMsBuildPath.Value(); command.InPlace = optInPlace.HasValue(); var success = command.ExecuteCommand(); return success ? 0 : 1; }); }); } return app.Execute(args); }
public async Task NuGetReader_DependencyInfoResource_DependencyGroupsAsync() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var outputRoot = Path.Combine(target.Root, "output"); var baseUri = UriUtility.CreateUri("https://localhost:8080/testFeed/"); var log = new TestLogger(); var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0", Dependencies = new List <PackageDependencyGroup>() { new PackageDependencyGroup(NuGetFramework.Parse("net46"), new List <PackageDependency>() { }), new PackageDependencyGroup(NuGetFramework.Parse("net45"), new[] { new PackageDependency("packageB", VersionRange.Parse("1.0.0")), new PackageDependency("packageC", VersionRange.Parse("2.0.0")) }), new PackageDependencyGroup(NuGetFramework.Parse("any"), new List <PackageDependency>() { new PackageDependency("packageB", VersionRange.Parse("1.0.0")) }) } } }; var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri); var sleetConfigPath = Path.Combine(target.Root, "sleet.config"); await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig); var zipFile = testPackage.Save(packagesFolder.Root); var settings = LocalSettings.Load(sleetConfigPath); var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, "local"); var success = await InitCommand.RunAsync(settings, fileSystem, log); // Act // Run sleet success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, false, false, log); // Create a repository abstraction for nuget var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri); var localSource = GetSource(outputRoot, baseUri, nugetFileSystem); var dependencyInfoResource = await localSource.GetResourceAsync <DependencyInfoResource>(); var dependencyPackagesNet46 = await dependencyInfoResource.ResolvePackages("packageA", NuGetFramework.Parse("net46"), log, CancellationToken.None); var dependencyPackageNet46 = dependencyPackagesNet46.Single(); var depString46 = string.Join("|", dependencyPackageNet46.Dependencies.Select(d => d.Id + " " + d.VersionRange.ToNormalizedString())); var dependencyPackagesNet45 = await dependencyInfoResource.ResolvePackages("packageA", NuGetFramework.Parse("net45"), log, CancellationToken.None); var dependencyPackageNet45 = dependencyPackagesNet45.Single(); var depString45 = string.Join("|", dependencyPackageNet45.Dependencies.Select(d => d.Id + " " + d.VersionRange.ToNormalizedString())); var dependencyPackagesNet40 = await dependencyInfoResource.ResolvePackages("packageA", NuGetFramework.Parse("net40"), log, CancellationToken.None); var dependencyPackageNet40 = dependencyPackagesNet40.Single(); var depString40 = string.Join("|", dependencyPackageNet40.Dependencies.Select(d => d.Id + " " + d.VersionRange.ToNormalizedString())); // Assert Assert.True(success, log.ToString()); Assert.Equal("https://localhost:8080/testFeed/flatcontainer/packagea/1.0.0/packagea.1.0.0.nupkg", dependencyPackageNet46.DownloadUri.AbsoluteUri); Assert.True(dependencyPackageNet46.Listed); Assert.Equal("packageA", dependencyPackageNet46.Id); Assert.Equal("1.0.0", dependencyPackageNet46.Version.ToNormalizedString()); Assert.Equal("", depString46); Assert.Equal("packageB [1.0.0, )|packageC [2.0.0, )", depString45); Assert.Equal("packageB [1.0.0, )", depString40); } }
public async Task RetentionPruneCommand_NoopsWhenNoPackagesNeedToBeRemoved() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("1.0.0")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0")), new PackageIdentity("a", NuGetVersion.Parse("4.0.0")), new PackageIdentity("a", NuGetVersion.Parse("5.0.0")), }; foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); } await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); var pruneContext = new RetentionPruneCommandContext() { StableVersionMax = 10, PrereleaseVersionMax = 10 }; // Run prune await RetentionPruneCommand.PrunePackages(context, pruneContext); // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert indexPackages.Count().Should().Be(5); } }
public async Task Feed_VerifyBaseUriIsAppliedToLocal(string baseUriString) { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystemRoot = UriUtility.CreateUri(target.Root); var baseUri = new Uri(baseUriString); var fileSystem = new PhysicalFileSystem(cache, fileSystemRoot, baseUri); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true } }; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(1, indexPackages.Count); Assert.Equal(1, searchPackages.Count); Assert.Equal(1, autoCompletePackages.Count); // Walk json to check for bad urls await TestUtility.WalkJsonAsync(target.Root, (file, json, toCheck) => { // Check only URLs found if (toCheck.IndexOf("://") > -1) { var cleanUriSchema = toCheck.Replace(":///", string.Empty).Replace("://", string.Empty); var doubleSlash = cleanUriSchema.IndexOf("//") > -1; Assert.False(doubleSlash, toCheck); } }); } } }
IEnumerator PreviewTrajectoryAndGiveRobotCommand() { Vector3 prevCursorPosition = Vector3.zero; Vector3 cursorPosition = Input.mousePosition; Vector3 cursorScreenPosition = Camera.main.ScreenToWorldPoint(cursorPosition); Command previewCommand = null; GameObject lastRobot = null; GameObject previewRobot; float timeBetweenPreivews = 0.1f; System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch(); Command.AvailableCommands prevSelectedCommand = selectedCommand; timer.Start(); while (selectedRobot != null) { cursorPosition = Input.mousePosition; cursorScreenPosition = Camera.main.ScreenToWorldPoint(cursorPosition); if (timeInput <= selectedRobot.GetComponent <RobotBehaviour>().freeTime&& timer.Elapsed.TotalSeconds > timeBetweenPreivews) { if (prevCursorPosition != cursorPosition || prevSelectedCommand != selectedCommand || RevertCommand() || lastRobot != selectedRobot) { timer.Reset(); timer.Start(); DestroyLatestPreviewTrail(); if (robotMovingTrails[selectedRobotIndex].Count > 0) { previewRobot = robotMovingTrails[selectedRobotIndex].Last().Node; } else { previewRobot = selectedRobot; } cursorPosition = Input.mousePosition; cursorScreenPosition = Camera.main.ScreenToWorldPoint(cursorPosition); if (selectedCommand == Command.AvailableCommands.Move) { previewCommand = new MoveCommand(previewRobot, cursorScreenPosition, timeInput, Turns); } else if (selectedCommand == Command.AvailableCommands.Push && timeInput <= selectedRobot.GetComponent <RobotBehaviour>().freeTime - shockWavePrefab.GetComponent <ShockwaveBehaviour>().intendedLifetime) { previewCommand = new PushCommand(previewRobot, cursorScreenPosition, timeInput, Turns); } else { Debug.Log("No command selected!"); } latestRobotTrail = new MovingTrail(previewCommand, timeInput, previewRobot.GetComponent <RobotBehaviour>().prevVelocity); //Not done yet! //if (latestRobotTrail != null && latestRobotTrail.Node != null) //{ // directionPointer = Instantiate(Resources.Load<GameObject>("Prefabs/Prototype stuff (remove or rework)/Direction Arrow")) as GameObject; // //directionPointer.transform.position = latestBallTrail.Node.transform.position; // //directionPointer.transform.parent = latestBallTrail.Node.transform; // float AngleRad = Mathf.Atan2(cursorPosition.y - directionPointer.transform.position.y, cursorPosition.x - directionPointer.transform.position.x); // float AngleDeg = (180 / Mathf.PI) * AngleRad; // directionPointer.transform.rotation = Quaternion.Euler(0, 0, AngleDeg); // directionPointer.name = "Direction Pointer"; //} } if (Input.GetMouseButtonDown(1) && latestRobotTrail != null) { latestRobotTrail.TrailGameObject.transform.parent = movingPreviews[selectedRobotIndex].transform; robotMovingTrails[selectedRobotIndex].Add(latestRobotTrail); latestRobotTrail = null; GiveRobotCommand(previewCommand); } } if (selectedRobot != lastRobot) { DestroyLatestPreviewTrail(); } prevCursorPosition = cursorPosition; prevSelectedCommand = selectedCommand; lastRobot = selectedRobot; yield return(new WaitForSeconds(0.005f)); } DestroyLatestPreviewTrail(); }
public async Task GivenThatIAddAPackageWithTheCatalogDisabledVerifyItSucceeds() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; context.SourceSettings.CatalogEnabled = false; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(input.Identity); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEquivalentTo(new[] { input.Identity }); indexPackages.Should().BeEquivalentTo(new[] { input.Identity }); searchPackages.Should().BeEquivalentTo(new[] { input.Identity }); autoCompletePackages.Should().BeEquivalentTo(new[] { input.Identity.Id }); catalogLatest.Should().BeNull(); catalogEntry["version"].ToString().Should().Be("1.0.0"); catalogEntry["sleet:operation"].ToString().Should().Be("add"); } } }
public async Task AddRemove_AddSinglePackage() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(1, indexPackages.Count); Assert.Equal(1, searchPackages.Count); Assert.Equal(1, autoCompletePackages.Count); Assert.Equal("packageA", catalogLatest.Id); Assert.Equal("1.0.0", catalogLatest.Version.ToIdentityString()); Assert.Equal(SleetOperation.Add, catalogLatest.Operation); } } }
public int Main(string[] args) { var app = new CommandLineApplication(); app.Name = "dnu"; app.FullName = "Microsoft .NET Development Utility"; var optionVerbose = app.Option("-v|--verbose", "Show verbose output", CommandOptionType.NoValue); app.HelpOption("-?|-h|--help"); app.VersionOption("--version", GetVersion); // Show help information if no subcommand/option was specified app.OnExecute(() => { app.ShowHelp(); return 2; }); app.Command("restore", c => { c.Description = "Restore packages"; var argRoot = c.Argument("[root]", "Root of all projects to restore. It can be a directory, a project.json, or a global.json."); var feedOptions = FeedOptions.Add(c); var optLock = c.Option("--lock", "Creates dependencies file with locked property set to true. Overwrites file if it exists.", CommandOptionType.NoValue); var optUnlock = c.Option("--unlock", "Creates dependencies file with locked property set to false. Overwrites file if it exists.", CommandOptionType.NoValue); var optParallel = c.Option("--parallel", "Restores in parallel when more than one project.json is discovered.", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var command = new RestoreCommand(_environment); command.Reports = CreateReports(optionVerbose.HasValue(), feedOptions.Quiet); command.RestoreDirectory = argRoot.Value; command.FeedOptions = feedOptions; command.Lock = optLock.HasValue(); command.Unlock = optUnlock.HasValue(); command.Parallel = optParallel.HasValue(); if (feedOptions.ProxyOptions.HasValue()) { Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy); } var success = await command.ExecuteCommand(); return success ? 0 : 1; }); }); app.Command("publish", c => { c.Description = "Publish application for deployment"; var argProject = c.Argument("[project]", "Path to project, default is current directory"); var optionOut = c.Option("-o|--out <PATH>", "Where does it go", CommandOptionType.SingleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "The configuration to use for deployment (Debug|Release|{Custom})", CommandOptionType.SingleValue); var optionNoSource = c.Option("--no-source", "Compiles the source files into NuGet packages", CommandOptionType.NoValue); var optionRuntime = c.Option("--runtime <RUNTIME>", "Name or full path of the runtime folder to include, or \"active\" for current runtime on PATH", CommandOptionType.MultipleValue); var optionNative = c.Option("--native", "Build and include native images. User must provide targeted CoreCLR runtime versions along with this option.", CommandOptionType.NoValue); var optionWwwRoot = c.Option("--wwwroot <NAME>", "Name of public folder in the project directory", CommandOptionType.SingleValue); var optionWwwRootOut = c.Option("--wwwroot-out <NAME>", "Name of public folder in the output, can be used only when the '--wwwroot' option or 'webroot' in project.json is specified", CommandOptionType.SingleValue); var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of published files", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var options = new PublishOptions { OutputDir = optionOut.Value(), ProjectDir = argProject.Value ?? System.IO.Directory.GetCurrentDirectory(), Configuration = optionConfiguration.Value() ?? "Debug", RuntimeTargetFramework = _environment.RuntimeFramework, WwwRoot = optionWwwRoot.Value(), WwwRootOut = optionWwwRootOut.Value() ?? optionWwwRoot.Value(), NoSource = optionNoSource.HasValue(), Runtimes = optionRuntime.HasValue() ? string.Join(";", optionRuntime.Values). Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries) : new string[0], Native = optionNative.HasValue(), Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()) }; var manager = new PublishManager(_hostServices, options); if (!manager.Publish()) { return -1; } return 0; }); }); app.Command("pack", c => { c.Description = "Build NuGet packages for the project in given directory"; var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue); var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue); var optionDependencies = c.Option("--dependencies", "Copy dependencies", CommandOptionType.NoValue); var optionQuiet = c.Option("--quiet", "Do not show output such as source/destination of nupkgs", CommandOptionType.NoValue); var argProjectDir = c.Argument("[project]", "Project to pack, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var buildOptions = new BuildOptions(); buildOptions.OutputDir = optionOut.Value(); buildOptions.ProjectDir = argProjectDir.Value ?? Directory.GetCurrentDirectory(); buildOptions.Configurations = optionConfiguration.Values; buildOptions.TargetFrameworks = optionFramework.Values; buildOptions.GeneratePackages = true; buildOptions.Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()); var projectManager = new BuildManager(_hostServices, buildOptions); if (!projectManager.Build()) { return -1; } return 0; }); }); app.Command("build", c => { c.Description = "Produce assemblies for the project in given directory"; var optionFramework = c.Option("--framework <TARGET_FRAMEWORK>", "A list of target frameworks to build.", CommandOptionType.MultipleValue); var optionConfiguration = c.Option("--configuration <CONFIGURATION>", "A list of configurations to build.", CommandOptionType.MultipleValue); var optionOut = c.Option("--out <OUTPUT_DIR>", "Output directory", CommandOptionType.SingleValue); var optionQuiet = c.Option("--quiet", "Do not show output such as dependencies in use", CommandOptionType.NoValue); var argProjectDir = c.Argument("[project]", "Project to build, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var buildOptions = new BuildOptions(); buildOptions.OutputDir = optionOut.Value(); buildOptions.ProjectDir = argProjectDir.Value ?? Directory.GetCurrentDirectory(); buildOptions.Configurations = optionConfiguration.Values; buildOptions.TargetFrameworks = optionFramework.Values; buildOptions.GeneratePackages = false; buildOptions.Reports = CreateReports(optionVerbose.HasValue(), optionQuiet.HasValue()); var projectManager = new BuildManager(_hostServices, buildOptions); if (!projectManager.Build()) { return -1; } return 0; }); }); app.Command("install", c => { c.Description = "Install the given dependency"; var argName = c.Argument("[name]", "Name of the dependency to add"); var argVersion = c.Argument("[version]", "Version of the dependency to add, default is the latest version."); var argProject = c.Argument("[project]", "Path to project, default is current directory"); var feedOptions = FeedOptions.Add(c); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var reports = CreateReports(optionVerbose.HasValue(), feedOptions.Quiet); var addCmd = new AddCommand(); addCmd.Reports = reports; addCmd.Name = argName.Value; addCmd.Version = argVersion.Value; addCmd.ProjectDir = argProject.Value; var restoreCmd = new RestoreCommand(_environment); restoreCmd.Reports = reports; restoreCmd.FeedOptions = feedOptions; restoreCmd.RestoreDirectory = argProject.Value; if (feedOptions.ProxyOptions.HasValue()) { Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy); } var installCmd = new InstallCommand(addCmd, restoreCmd); installCmd.Reports = reports; var success = await installCmd.ExecuteCommand(); return success ? 0 : 1; }); }); app.Command("packages", packagesCommand => { packagesCommand.Description = "Commands related to managing local and remote packages folders"; packagesCommand.HelpOption("-?|-h|--help"); packagesCommand.OnExecute(() => { packagesCommand.ShowHelp(); return 2; }); packagesCommand.Command("add", c => { c.Description = "Add a NuGet package to the specified packages folder"; var argNupkg = c.Argument("[nupkg]", "Path to a NuGet package"); var argSource = c.Argument("[source]", "Path to packages folder"); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var options = new AddOptions { Reports = CreateReports(optionVerbose.HasValue(), quiet: false), SourcePackages = argSource.Value, NuGetPackage = argNupkg.Value }; var command = new Packages.AddCommand(options); var success = await command.Execute(); return success ? 0 : 1; }); }); packagesCommand.Command("push", c => { c.Description = "Incremental copy of files from local packages to remote location"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); // Implicitly commit changes before push var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); var success = commitCommand.Execute(); if (!success) { return 1; } var pushOptions = new PushOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pushCommand = new PushCommand(pushOptions); success = pushCommand.Execute(); return success ? 0 : 1; }); }); packagesCommand.Command("pull", c => { c.Description = "Incremental copy of files from remote location to local packages"; var argRemote = c.Argument("[remote]", "Path to remote packages folder"); var argSource = c.Argument("[source]", "Path to source packages folder, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); bool success; if (Directory.Exists(argSource.Value)) { // Implicitly commit changes before pull var commitOptions = new CommitOptions { Reports = reports, SourcePackages = argSource.Value }; var commitCommand = new CommitCommand(commitOptions); success = commitCommand.Execute(); if (!success) { return 1; } } var pullOptions = new PullOptions { Reports = reports, SourcePackages = argSource.Value, RemotePackages = argRemote.Value }; var pullCommand = new PullCommand(pullOptions); success = pullCommand.Execute(); return success ? 0 : 1; }); }); }); app.Command("list", c => { c.Description = "Print the dependencies of a given project"; var showAssemblies = c.Option("-a|--assemblies", "Show the assembly files that are depended on by given project", CommandOptionType.NoValue); var frameworks = c.Option("--framework <TARGET_FRAMEWORK>", "Show dependencies for only the given frameworks", CommandOptionType.MultipleValue); var runtimeFolder = c.Option("--runtime <PATH>", "The folder containing all available framework assemblies", CommandOptionType.SingleValue); var hideDependents = c.Option("--hide-dependents", "Hide the immediate dependents of libraries referenced in the project", CommandOptionType.NoValue); var resultsFilter = c.Option("--filter <PATTERN>", "Filter the libraries referenced by the project base on their names. The matching pattern supports * and ?", CommandOptionType.SingleValue); var argProject = c.Argument("[project]", "Path to project, default is current directory"); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var options = new DependencyListOptions(CreateReports(verbose: true, quiet: false), argProject) { TargetFrameworks = frameworks.Values, ShowAssemblies = showAssemblies.HasValue(), RuntimeFolder = runtimeFolder.Value(), HideDependents = hideDependents.HasValue(), ResultsFilter = resultsFilter.Value() }; if (!options.Valid) { if (options.Project == null) { options.Reports.Error.WriteLine(string.Format("Unable to locate {0}.".Red(), Runtime.Project.ProjectFileName)); return 1; } else { options.Reports.Error.WriteLine("Invalid options.".Red()); return 2; } } var command = new DependencyListCommand(options, _environment.RuntimeFramework); return command.Execute(); }); }); app.Command("commands", cmd => { cmd.Description = "Commands related to managing application commands (add, remove)"; cmd.HelpOption("-?|-h|--help"); cmd.OnExecute(() => { cmd.ShowHelp(); return 2; }); cmd.Command("install", c => { c.Description = "Installs application commands"; var argPackage = c.Argument("[package]", "The name of the application package"); var argVersion = c.Argument("[version]", "The version of the application package"); var optOverwrite = c.Option("-o|--overwrite", "Overwrites conflicting commands", CommandOptionType.NoValue); var feedOptions = FeedOptions.Add(c); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { var command = new InstallGlobalCommand( _environment, string.IsNullOrEmpty(feedOptions.TargetPackagesFolder) ? AppCommandsFolderRepository.CreateDefault() : AppCommandsFolderRepository.Create(feedOptions.TargetPackagesFolder)); command.FeedOptions = feedOptions; command.Reports = CreateReports(optionVerbose.HasValue(), feedOptions.Quiet); command.OverwriteCommands = optOverwrite.HasValue(); if (feedOptions.Proxy != null) { Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy); } var success = await command.Execute(argPackage.Value, argVersion.Value); return success ? 0 : 1; }); }); cmd.Command("uninstall", c => { c.Description = "Uninstalls application commands"; var argCommand = c.Argument("[command]", "The name of the command to uninstall"); var optNoPurge = c.Option("--no-purge", "Do not try to remove orphaned packages", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var command = new UninstallCommand( _environment, AppCommandsFolderRepository.CreateDefault(), reports: CreateReports(optionVerbose.HasValue(), quiet: false)); command.NoPurge = optNoPurge.HasValue(); var success = command.Execute(argCommand.Value); return success ? 0 : 1; }); }); }); app.Command("wrap", c => { c.Description = "Wrap a csproj into a project.json, which can be referenced by project.json files"; var argPath = c.Argument("[path]", "Path to csproj to be wrapped"); var optConfiguration = c.Option("--configuration <CONFIGURATION>", "Configuration of wrapped project, default is 'debug'", CommandOptionType.SingleValue); var optMsBuildPath = c.Option("--msbuild <PATH>", @"Path to MSBuild, default is '%ProgramFiles%\MSBuild\14.0\Bin\MSBuild.exe'", CommandOptionType.SingleValue); var optInPlace = c.Option("-i|--in-place", "Generate or update project.json files in project directories of csprojs", CommandOptionType.NoValue); var optFramework = c.Option("-f|--framework", "Target framework of assembly to be wrapped", CommandOptionType.SingleValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { var reports = CreateReports(optionVerbose.HasValue(), quiet: false); var command = new WrapCommand(); command.Reports = reports; command.InputFilePath = argPath.Value; command.Configuration = optConfiguration.Value(); command.MsBuildPath = optMsBuildPath.Value(); command.InPlace = optInPlace.HasValue(); command.Framework = optFramework.Value(); var success = command.ExecuteCommand(); return success ? 0 : 1; }); }); return app.Execute(args); }