public static void Restore(RavenConfiguration configuration, RestoreRequest restoreRequest, Action<string> output) { var databaseDocumentPath = Path.Combine(restoreRequest.BackupLocation, "Database.Document"); if (File.Exists(databaseDocumentPath) == false) { throw new InvalidOperationException("Cannot restore when the Database.Document file is missing in the backup folder: " + restoreRequest.BackupLocation); } var databaseDocumentText = File.ReadAllText(databaseDocumentPath); var databaseDocument = RavenJObject.Parse(databaseDocumentText).JsonDeserialization<DatabaseDocument>(); string storage; if (databaseDocument.Settings.TryGetValue("Raven/StorageTypeName", out storage) == false) { storage = "esent"; } if (!string.IsNullOrWhiteSpace(restoreRequest.DatabaseLocation)) { configuration.DataDirectory = restoreRequest.DatabaseLocation; } using (var transactionalStorage = configuration.CreateTransactionalStorage(storage, () => { })) { transactionalStorage.Restore(restoreRequest, output); } }
protected BaseRestoreOperation(RestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action<string> output) { _restoreRequest = restoreRequest; backupLocation = restoreRequest.BackupLocation; databaseLocation = _restoreRequest.DatabaseLocation.ToFullPath(); indexLocation = (_restoreRequest.IndexesLocation ?? Path.Combine(_restoreRequest.DatabaseLocation, "Indexes")).ToFullPath(); journalLocation = (_restoreRequest.JournalsLocation ?? _restoreRequest.DatabaseLocation).ToFullPath(); Configuration = configuration; this.output = output; }
public RestoreRequestTests() { var request = new RestoreRequest("repos", "snap") { IgnoreUnavailable = true, IncludeGlobalState = true, WaitForCompletion = true, RenamePattern = "index_(.+)", RenameReplacement = "index_restored_$1" }; var response = this._client.Restore(request); this._status = response.ConnectionStatus; }
public void RestoreSite(string resourceGroupName, string webSiteName, string slotName, string backupId, RestoreRequest request) { string qualifiedSiteName; var useSlot = CmdletHelpers.ShouldUseDeploymentSlot(webSiteName, slotName, out qualifiedSiteName); if (useSlot) { WrappedWebsitesClient.WebApps().RestoreSlot( resourceGroupName, webSiteName, backupId, request, slotName); } else { WrappedWebsitesClient.WebApps().Restore(resourceGroupName, webSiteName, backupId, request); } }
public async Task <string> CreateRequest(string userId) { var previousRequests = db.RestoreRequests.Where(r => r.UserId == userId).ToList(); if (previousRequests.Any()) { var hasRecent = false; foreach (var previous in previousRequests) { if (DateTime.Now.Subtract(previous.Timestamp) < TimeSpan.FromMinutes(5)) { hasRecent = true; } else { db.RestoreRequests.Remove(previous); } } if (hasRecent) { await db.SaveChangesAsync(); return(null); } } var request = new RestoreRequest { Id = Guid.NewGuid().ToString(), UserId = userId, Timestamp = DateTime.Now }; db.RestoreRequests.Add(request); await db.SaveChangesAsync(); return(request.Id); }
public virtual ArmOperation RestoreSlot(WaitUntil waitUntil, RestoreRequest request, CancellationToken cancellationToken = default) { Argument.AssertNotNull(request, nameof(request)); using var scope = _siteSlotBackupWebAppsClientDiagnostics.CreateScope("SiteSlotBackupResource.RestoreSlot"); scope.Start(); try { var response = _siteSlotBackupWebAppsRestClient.RestoreSlot(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, request, cancellationToken); var operation = new AppServiceArmOperation(_siteSlotBackupWebAppsClientDiagnostics, Pipeline, _siteSlotBackupWebAppsRestClient.CreateRestoreSlotRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, request).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) { operation.WaitForCompletionResponse(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public static List <string> ListAssemblies(RestoreRequest request, RestoreResult result) { var assemblies = new List <string>(); foreach (var library in result.LockFile.Libraries) { // Try several known path (note: order matters) foreach (var startPattern in new[] { "runtimes/win7-d3d11/lib/net4", "runtimes/win/lib/net4", "lib/net4", "lib/net35", "lib/netstandard2.", "lib/netstandard1.", "lib/net10" }) { foreach (var file in library.Files) { var extension = Path.GetExtension(file).ToLowerInvariant(); // Try several known path (note: order matters) if (file.StartsWith(startPattern, StringComparison.InvariantCultureIgnoreCase) && (extension == ".dll" || extension == ".exe")) { assemblies.Add(Path.Combine(request.DependencyProviders.GlobalPackages.RepositoryRoot, library.Path, file)); } } } } return(assemblies); }
public void ShouldCallRecoveryStatus_Rename() { var elastickClientMock = new Mock <IElasticClient>(); RestoreRequest restoreRequestFixture = RestoreRequestFixture("test_tmp"); restoreRequestFixture.RenamePattern = "_(.+)"; restoreRequestFixture.RenameReplacement = "_restored_$1"; var sut = new RestoreStatusHumbleObject(elastickClientMock.Object, restoreRequestFixture); sut.CheckStatus(); elastickClientMock.Verify(x => x .RecoveryStatus( It.Is <RecoveryStatusRequest>( request => request.Indices.Count() == 1 && request.Indices.ElementAt(0).Name == Regex.Replace("test_tmp", restoreRequestFixture.RenamePattern, restoreRequestFixture.RenameReplacement) && request.Indices.ElementAt(0).Type == typeof(object) && request.Detailed)), Times.AtLeastOnce); }
public override void ExecuteCmdlet() { base.ExecuteCmdlet(); if (string.IsNullOrEmpty(AppServicePlan)) { Site app = WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot); this.AppServicePlan = app.ServerFarmId.Split('/').Last(); } RestoreRequest request = new RestoreRequest() { StorageAccountUrl = this.StorageAccountUrl, BlobName = this.BlobName, SiteName = CmdletHelpers.GenerateSiteWithSlotName(Name, Slot), Overwrite = this.Overwrite.IsPresent, AppServicePlan = this.AppServicePlan, IgnoreConflictingHostNames = this.IgnoreConflictingHostNames.IsPresent, Databases = this.Databases, OperationType = BackupRestoreOperationType.Default }; // The id here does not actually matter. It is an artifact of the CSM API requirements. It should be possible // to restore from a backup that is no longer stored in our Backups table. WebsitesClient.RestoreSite(ResourceGroupName, Name, Slot, "1", request); }
public virtual SiteSlotBackupRestoreSlotOperation RestoreSlot(bool waitForCompletion, RestoreRequest request, CancellationToken cancellationToken = default) { if (request == null) { throw new ArgumentNullException(nameof(request)); } using var scope = _siteSlotBackupWebAppsClientDiagnostics.CreateScope("SiteSlotBackup.RestoreSlot"); scope.Start(); try { var response = _siteSlotBackupWebAppsRestClient.RestoreSlot(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, request, cancellationToken); var operation = new SiteSlotBackupRestoreSlotOperation(_siteSlotBackupWebAppsClientDiagnostics, Pipeline, _siteSlotBackupWebAppsRestClient.CreateRestoreSlotRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Parent.Name, Id.Parent.Name, Id.Name, request).Request, response); if (waitForCompletion) { operation.WaitForCompletionResponse(cancellationToken); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public void Restore(RestoreRequest restoreRequest, Action<string> output) { new RestoreOperation(restoreRequest, configuration, output).Execute(); }
public async Task Project2ProjectInLockFile_VerifySnapshotVersionsXProj() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""2.0.0-*"", ""description"": ""Proj1 Class Library"", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""dependencies"": { ""project2"": ""2.0.0-*"" }, ""frameworks"": { ""net45"": { } } }"; var project2Json = @" { ""version"": ""2.0.0-*"", ""description"": ""Proj2 Class Library"", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""net45"": { } } }"; var globalJson = @" { ""projects"": [ ""projects"" ] }"; using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); var project2 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project2")); project1.Create(); project2.Create(); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); File.WriteAllText(Path.Combine(project2.FullName, "project.json"), project2Json); File.WriteAllText(Path.Combine(workingDir, "global.json"), globalJson); File.WriteAllText(Path.Combine(project1.FullName, "project1.csproj"), string.Empty); File.WriteAllText(Path.Combine(project2.FullName, "project2.xproj"), string.Empty); var specPath1 = Path.Combine(project1.FullName, "project.json"); var specPath2 = Path.Combine(project2.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var spec2 = JsonPackageSpecReader.GetPackageSpec(project2Json, "project2", specPath2); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); var format = new LockFileFormat(); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var lockFile = format.Read(request.LockFilePath, logger); var project2Lib = lockFile.GetLibrary("project2", NuGetVersion.Parse("2.0.0")); var project2Target = lockFile.GetTarget(FrameworkConstants.CommonFrameworks.Net45, runtimeIdentifier: null) .Libraries .Single(lib => lib.Name == "project2"); // Assert Assert.True(result.Success); Assert.Equal("2.0.0", project2Target.Version.ToString()); Assert.Equal("2.0.0", project2Lib.Version.ToString()); } }
async Task RestorePackagesAsync( IEnumerable <InteractivePackage> packages, SourceCacheContext cacheContext, CancellationToken cancellationToken) { var restoreContext = new RestoreArgs { CacheContext = cacheContext, Log = Logger, }; // NOTE: This path is typically empty. It could in theory contain nuget.config settings // files, but really we just use it to satisfy nuget API that requires paths, // even when they are never used. var rootPath = packageConfigDirectory; var globalPath = restoreContext.GetEffectiveGlobalPackagesFolder(rootPath, settings); var fallbackPaths = restoreContext.GetEffectiveFallbackPackageFolders(settings); var providerCache = new RestoreCommandProvidersCache(); var restoreProviders = providerCache.GetOrCreate( globalPath, fallbackPaths, SourceRepositories, cacheContext, Logger); // Set up a project spec similar to what you would see in a project.json. // This is sufficient for the dependency graph work done within RestoreCommand. // TODO: XF version pinning during restore? var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = TargetFramework, Dependencies = packages.Select(ToLibraryDependency).ToList(), }; var projectSpec = new PackageSpec(new [] { targetFrameworkInformation }) { Name = project.Name, FilePath = rootPath, }; var restoreRequest = new RestoreRequest(projectSpec, restoreProviders, cacheContext, Logger); var restoreCommand = new RestoreCommand(restoreRequest); var result = await restoreCommand.ExecuteAsync(cancellationToken); if (!result.Success) { return; } project.ResetInstallationContext(); // As with installation, restore simply ensures that packages are present in the user's // global package cache. We reference them out of there just like .NET core projects do. // // All resolved packages, including the explicit inputs and their dependencies, are // available as LockFileLibrary instances. foreach (var library in result.LockFile.Libraries) { project.InstallationContext.AddInstalledPackage( GetInteractivePackageFromLibrary(library, project, packages)); } installedPackages = project.InstallationContext.InstalledPackages; UpdateInstalledPackages(); }
/// <summary> /// Evaluate the location of the cache file path, based on ProjectStyle. /// </summary> internal static string GetCacheFilePath(RestoreRequest request) { return(GetCacheFilePath(request, lockFile: null)); }
public Task StartRestoreAsync(RestoreRequest restoreRequest) { var request = adminRequest.CreateRestoreRequest(); return(request.WriteAsync(RavenJObject.FromObject(restoreRequest))); }
public RestoreOperation(RestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action <string> operationOutputCallback) : base(restoreRequest, configuration, operationOutputCallback) { }
public static void RestoreSite(this IWebAppsOperations webApp, string resourceGroupName, string name, string backupId, RestoreRequest request) { webApp.Restore(resourceGroupName, name, backupId, request); }
public async Task CompatilibityChecker_PackageCompatibility_VerifyNoAvailableFrameworks() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""netstandard1.0"": { ""dependencies"": { ""packageA"": { ""version"": ""1.0.0"" } } } } }"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var packagesDir = new DirectoryInfo(Path.Combine(workingDir, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(workingDir, "packageSource")); var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); packagesDir.Create(); packageSource.Create(); project1.Create(); sources.Add(new PackageSource(packageSource.FullName)); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); var specPath1 = Path.Combine(project1.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir.FullName, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); var packageA = new SimpleTestPackageContext("packageA"); packageA.AddFile("ref/a.dll"); SimpleTestPackageUtility.CreatePackages(packageSource.FullName, packageA); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); // Assert Assert.False(result.Success, logger.ShowErrors()); // Verify both libraries were installed Assert.Equal(1, result.LockFile.Libraries.Count); var issue = result.CompatibilityCheckResults.SelectMany(check => check.Issues).Single(); Assert.Equal(@"Package packageA 1.0.0 is not compatible with netstandard1.0 (.NETStandard,Version=v1.0). Package packageA 1.0.0 does not support any target frameworks.".Replace("\n", Environment.NewLine), issue.Format()); } }
public async Task CompatilibityChecker_RuntimeFoundInSamePackage_Success() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""netstandard1.5"": { ""dependencies"": { ""packageA"": { ""version"": ""1.0.0"" } } } } }"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var packagesDir = new DirectoryInfo(Path.Combine(workingDir, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(workingDir, "packageSource")); var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); packagesDir.Create(); packageSource.Create(); project1.Create(); sources.Add(new PackageSource(packageSource.FullName)); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); var specPath1 = Path.Combine(project1.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir.FullName, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); request.RequestedRuntimes.Add("win7-x86"); var packageA = new SimpleTestPackageContext("packageA"); packageA.AddFile("ref/netstandard1.3/a.dll"); packageA.AddFile("ref/netstandard1.3/b.dll"); packageA.AddFile("ref/netstandard1.3/c.dll"); packageA.AddFile("runtimes/win7-x86/lib/netstandard1.1/a.dll"); packageA.AddFile("runtimes/win7-x86/lib/netstandard1.1/b.ni.dll"); packageA.AddFile("runtimes/win7-x86/lib/netstandard1.1/c.dll"); SimpleTestPackageUtility.CreatePackages(packageSource.FullName, packageA); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); // Assert Assert.True(result.Success, logger.ShowErrors()); // Verify both libraries were installed Assert.Equal(1, result.LockFile.Libraries.Count); // Verify no compatibility issues Assert.True(result.CompatibilityCheckResults.All(check => check.Success)); } }
protected override bool CanRestore(RestoreRequest <InstanceIdParameters> Operation) { return(HasPermission(Operation.Key.InstanceId)); }
public int Main(string[] args) { #if DEBUG if (args.Contains("--debug")) { args = args.Skip(1).ToArray(); System.Diagnostics.Debugger.Launch(); } #endif // Set up logging _log = new CommandOutputLogger(); var app = new CommandLineApplication(); app.Name = "nuget3"; app.FullName = ".NET Package Manager"; app.HelpOption("-h|--help"); app.VersionOption("--version", GetType().GetTypeInfo().Assembly.GetName().Version.ToString()); app.Command("restore", restore => { restore.Description = "Restores packages for a project and writes a lock file"; var sources = restore.Option("-s|--source <source>", "Specifies a NuGet package source to use during the restore", CommandOptionType.MultipleValue); var packagesDirectory = restore.Option("--packages <packagesDirectory>", "Directory to install packages in", CommandOptionType.SingleValue); var parallel = restore.Option("-p|--parallel <noneOrNumberOfParallelTasks>", $"The number of concurrent tasks to use when restoring. Defaults to {RestoreRequest.DefaultDegreeOfConcurrency}; pass 'none' to run without concurrency.", CommandOptionType.SingleValue); var projectFile = restore.Argument("[project file]", "The path to the project to restore for, either a project.json or the directory containing it. Defaults to the current directory"); restore.OnExecute(async() => { // Figure out the project directory IEnumerable <string> externalProjects = null; PackageSpec project; var projectPath = Path.GetFullPath(projectFile.Value ?? "."); if (string.Equals(PackageSpec.PackageSpecFileName, Path.GetFileName(projectPath), StringComparison.OrdinalIgnoreCase)) { _log.LogVerbose($"Reading project file {projectFile.Value}"); projectPath = Path.GetDirectoryName(projectPath); project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(projectFile.Value), Path.GetFileName(projectPath), projectFile.Value); } else if (MsBuildUtility.IsMsBuildBasedProject(projectPath)) { #if DNXCORE50 throw new NotSupportedException(); #else externalProjects = MsBuildUtility.GetProjectReferences(projectPath); projectPath = Path.GetDirectoryName(Path.GetFullPath(projectPath)); var packageSpecFile = Path.Combine(projectPath, PackageSpec.PackageSpecFileName); project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(packageSpecFile), Path.GetFileName(projectPath), projectFile.Value); _log.LogVerbose($"Reading project file {projectFile.Value}"); #endif } else { var file = Path.Combine(projectPath, PackageSpec.PackageSpecFileName); _log.LogVerbose($"Reading project file {file}"); project = JsonPackageSpecReader.GetPackageSpec(File.ReadAllText(file), Path.GetFileName(projectPath), file); } _log.LogVerbose($"Loaded project {project.Name} from {project.FilePath}"); // Resolve the root directory var rootDirectory = PackageSpecResolver.ResolveRootDirectory(projectPath); _log.LogVerbose($"Found project root directory: {rootDirectory}"); // Resolve the packages directory var packagesDir = packagesDirectory.HasValue() ? packagesDirectory.Value() : Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE"), ".nuget", "packages"); _log.LogVerbose($"Using packages directory: {packagesDir}"); var packageSources = sources.Values.Select(s => new PackageSource(s)); if (!packageSources.Any()) { var settings = Settings.LoadDefaultSettings(projectPath, configFileName: null, machineWideSettings: null); var packageSourceProvider = new PackageSourceProvider(settings); packageSources = packageSourceProvider.LoadPackageSources(); } var request = new RestoreRequest( project, packageSources, packagesDir); if (externalProjects != null) { foreach (var externalReference in externalProjects) { request.ExternalProjects.Add( new ExternalProjectReference( externalReference, Path.Combine(Path.GetDirectoryName(externalReference), PackageSpec.PackageSpecFileName), projectReferences: Enumerable.Empty <string>())); } } // Run the restore if (parallel.HasValue()) { int parallelDegree; if (string.Equals(parallel.Value(), "none", StringComparison.OrdinalIgnoreCase)) { request.MaxDegreeOfConcurrency = 1; } else if (int.TryParse(parallel.Value(), out parallelDegree)) { request.MaxDegreeOfConcurrency = parallelDegree; } } if (request.MaxDegreeOfConcurrency <= 1) { _log.LogInformation("Running non-parallel restore"); } else { _log.LogInformation($"Running restore with {request.MaxDegreeOfConcurrency} concurrent jobs"); } var command = new RestoreCommand(_log); var sw = Stopwatch.StartNew(); var result = await command.ExecuteAsync(request); sw.Stop(); _log.LogInformation($"Restore completed in {sw.ElapsedMilliseconds:0.00}ms!"); return(0); }); }); app.Command("diag", diag => { diag.Description = "Diagnostic commands for debugging package dependency graphs"; diag.Command("lockfile", lockfile => { lockfile.Description = "Dumps data from the project lock file"; var project = lockfile.Option("--project <project>", "Path containing the project lockfile, or the patht to the lockfile itself", CommandOptionType.SingleValue); var target = lockfile.Option("--target <target>", "View information about a specific project target", CommandOptionType.SingleValue); var library = lockfile.Argument("<library>", "Optionally, get detailed information about a specific library"); lockfile.OnExecute(() => { var diagnostics = new DiagnosticCommands(_log); var projectFile = project.HasValue() ? project.Value() : Path.GetFullPath("."); return(diagnostics.Lockfile(projectFile, target.Value(), library.Value)); }); }); diag.OnExecute(() => { diag.ShowHelp(); return(0); }); }); app.OnExecute(() => { app.ShowHelp(); return(0); }); return(app.Execute(args)); }
public async Task MinClientVersion_DependencyVersionTooHigh() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""netstandard1.3"": { ""dependencies"": { ""packageA"": ""1.0.0"" } } } }"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var packagesDir = new DirectoryInfo(Path.Combine(workingDir, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(workingDir, "packageSource")); var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); packagesDir.Create(); packageSource.Create(); project1.Create(); sources.Add(new PackageSource(packageSource.FullName)); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); var specPath1 = Path.Combine(project1.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir.FullName, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); var packageBContext = new SimpleTestPackageContext() { Id = "packageB", Version = "1.0.0", MinClientVersion = "9.0.0" }; var packageAContext = new SimpleTestPackageContext() { Id = "packageA", Version = "1.0.0", MinClientVersion = "1.0.0", Dependencies = new List <SimpleTestPackageContext>() { packageBContext } }; SimpleTestPackageUtility.CreatePackages(packageSource.FullName, packageAContext, packageBContext); Exception ex = null; // Act var command = new RestoreCommand(request); try { var result = await command.ExecuteAsync(); } catch (Exception exception) { ex = exception; } // Assert Assert.Contains("The 'packageB 1.0.0' package requires NuGet client version '9.0.0' or above, but the current NuGet version is", ex.Message); } }
public void Restore(RestoreRequest restoreRequest, Action <string> output) { new RestoreOperation(restoreRequest, configuration, output).Execute(); }
public RestoreOperation(RestoreRequest restoreRequest, InMemoryRavenConfiguration configuration, Action<string> operationOutputCallback) : base(restoreRequest, configuration, operationOutputCallback) { }
public async Task Project2ProjectInLockFile_VerifyProjectsReferencesInLibAndTargets() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""dependencies"": { ""project2"": ""1.0.0-*"", }, ""frameworks"": { ""net45"": {} } }"; var project2Json = @" { ""version"": ""1.0.0"", ""dependencies"": { ""project3"": ""1.0.0-*"", }, ""frameworks"": { ""net45"": {} } }"; var project3Json = @" { ""version"": ""1.0.0"", ""dependencies"": { }, ""frameworks"": { ""net45"": {} } }"; var globalJson = @" { ""projects"": [ ""projects"" ] }"; using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); var project2 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project2")); var project3 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project3")); project1.Create(); project2.Create(); project3.Create(); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); File.WriteAllText(Path.Combine(project2.FullName, "project.json"), project2Json); File.WriteAllText(Path.Combine(project3.FullName, "project.json"), project3Json); File.WriteAllText(Path.Combine(workingDir, "global.json"), globalJson); File.WriteAllText(Path.Combine(project1.FullName, "project1.xproj"), string.Empty); File.WriteAllText(Path.Combine(project2.FullName, "project2.xproj"), string.Empty); File.WriteAllText(Path.Combine(project3.FullName, "project3.xproj"), string.Empty); var specPath1 = Path.Combine(project1.FullName, "project.json"); var spec = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var specPath2 = Path.Combine(project2.FullName, "project.json"); var specPath3 = Path.Combine(project3.FullName, "project.json"); var logger = new TestLogger(); var request = new RestoreRequest(spec, sources, packagesDir, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); var format = new LockFileFormat(); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var lockFile = format.Read(request.LockFilePath, logger); var project1Lib = lockFile.GetLibrary("project1", NuGetVersion.Parse("1.0.0")); var project2Lib = lockFile.GetLibrary("project2", NuGetVersion.Parse("1.0.0")); var project3Lib = lockFile.GetLibrary("project3", NuGetVersion.Parse("1.0.0")); var project2Target = lockFile.GetTarget(FrameworkConstants.CommonFrameworks.Net45, runtimeIdentifier: null) .Libraries .Where(lib => lib.Name == "project2") .Single(); var project3Target = lockFile.GetTarget(FrameworkConstants.CommonFrameworks.Net45, runtimeIdentifier: null) .Libraries .Where(lib => lib.Name == "project3") .Single(); // Assert Assert.True(result.Success); Assert.Equal(2, lockFile.Libraries.Count); Assert.Equal("project", project2Lib.Type); Assert.Equal("project", project3Lib.Type); Assert.Equal("../project2/project.json", project2Lib.Path); Assert.Equal("../project3/project.json", project3Lib.Path); Assert.Equal("../project2/project2.xproj", project2Lib.MSBuildProject); Assert.Equal("../project3/project3.xproj", project3Lib.MSBuildProject); Assert.Equal(1, project2Target.CompileTimeAssemblies.Count); Assert.Equal("net45/project2.dll", project2Target.CompileTimeAssemblies.Single().Path); Assert.Equal(1, project3Target.CompileTimeAssemblies.Count); Assert.Equal("net45/project3.dll", project3Target.CompileTimeAssemblies.Single().Path); Assert.Equal(1, project2Target.Dependencies.Count); Assert.Equal("project3", project2Target.Dependencies.Single().Id); Assert.Equal("1.0.0", project2Target.Dependencies.Single().VersionRange.ToLegacyShortString()); Assert.Equal(0, project3Target.Dependencies.Count); Assert.Equal(".NETFramework,Version=v4.5", project2Target.Framework); Assert.Equal(".NETFramework,Version=v4.5", project3Target.Framework); } }
public void StartRestore(RestoreRequest restoreRequest) { asyncAdminServerClient.StartRestoreAsync(restoreRequest).WaitUnwrap(); }
public async Task UWPRestore_BlankUWPAppV1() { // Arrange var sources = new List <PackageSource>(); sources.Add(new PackageSource("https://api.nuget.org/v3/index.json")); using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder()) { var configJson = JObject.Parse(@"{ ""dependencies"": { ""Microsoft.NETCore.UniversalWindowsPlatform"": ""5.0.0"" }, ""frameworks"": { ""uap10.0"": {} }, ""runtimes"": { ""win10-arm"": {}, ""win10-arm-aot"": {}, ""win10-x86"": {}, ""win10-x86-aot"": {}, ""win10-x64"": {}, ""win10-x64-aot"": {} } }"); var specPath = Path.Combine(projectDir, "TestProject", "project.json"); var spec = JsonPackageSpecReader.GetPackageSpec(configJson.ToString(), "TestProject", specPath); var logger = new TestLogger(); var request = new RestoreRequest(spec, sources, packagesDir, logger); request.LockFilePath = Path.Combine(projectDir, "project.lock.json"); // Set the lock file version to v1 to force a downgrade request.LockFileVersion = 1; var lockFileFormat = new LockFileFormat(); var command = new RestoreCommand(request); var expectedStream = GetResource("NuGet.Commands.FuncTest.compiler.resources.uwpBlankAppV1.json"); JObject expectedJson = null; using (var reader = new StreamReader(expectedStream)) { expectedJson = JObject.Parse(reader.ReadToEnd()); } // Act var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var lockFileJson = JObject.Parse(File.OpenText(request.LockFilePath).ReadToEnd()); RemovePackageFolders(lockFileJson); // Assert Assert.True(result.Success); Assert.Equal(0, result.CompatibilityCheckResults.Sum(checkResult => checkResult.Issues.Count)); Assert.Equal(0, logger.Errors); Assert.Equal(0, logger.Warnings); Assert.Equal(118, result.GetAllInstalled().Count); Assert.Equal(expectedJson.ToString(), lockFileJson.ToString()); } }
/// <summary> /// If the dependencyGraphSpec is not set, we cannot no-op on this project restore. /// </summary> internal static bool IsNoOpSupported(RestoreRequest request) { return(request.DependencyGraphSpec != null); }
public async virtual Task <ArmOperation> RestoreAsync(bool waitForCompletion, RestoreRequest request, CancellationToken cancellationToken = default) { Argument.AssertNotNull(request, nameof(request)); using var scope = _siteBackupWebAppsClientDiagnostics.CreateScope("SiteBackup.Restore"); scope.Start(); try { var response = await _siteBackupWebAppsRestClient.RestoreAsync(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, request, cancellationToken).ConfigureAwait(false); var operation = new AppServiceArmOperation(_siteBackupWebAppsClientDiagnostics, Pipeline, _siteBackupWebAppsRestClient.CreateRestoreRequest(Id.SubscriptionId, Id.ResourceGroupName, Id.Parent.Name, Id.Name, request).Request, response, OperationFinalStateVia.Location); if (waitForCompletion) { await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task RestoreTargets_RestoreWithRuntimes() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""netstandardapp1.5"": { ""dependencies"": { ""packageA"": ""1.0.0"" } } } }"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var packagesDir = new DirectoryInfo(Path.Combine(workingDir, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(workingDir, "packageSource")); var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); packagesDir.Create(); packageSource.Create(); project1.Create(); sources.Add(new PackageSource(packageSource.FullName)); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); var specPath1 = Path.Combine(project1.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir.FullName, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); request.RequestedRuntimes.Add("win7-x86"); var packageA = new SimpleTestPackageContext() { Id = "packageA" }; packageA.AddFile("lib/netstandard1.5/a.dll"); packageA.AddFile("native/a.dll"); packageA.AddFile("runtimes/unix/native/a.dll"); packageA.AddFile("runtimes/unix/lib/netstandard1.5/a.dll"); packageA.AddFile("runtimes/win7/lib/netstandard1.5/a.dll"); packageA.AddFile("runtimes/win7-x86/lib/netstandard1.5/a.dll"); packageA.AddFile("runtimes/win7-x86/lib/netstandard1.5/en-us/a.resources.dll"); SimpleTestPackageUtility.CreatePackages(packageSource.FullName, packageA); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var format = new LockFileFormat(); var lockFile = format.Read(request.LockFilePath); var targetLib = lockFile.Targets.Single(graph => graph.RuntimeIdentifier == null).Libraries.Single(); var ridTargetLib = lockFile.Targets.Single(graph => graph.RuntimeIdentifier != null).Libraries.Single(); // Assert Assert.True(result.Success); Assert.Equal(5, targetLib.RuntimeTargets.Count); Assert.Equal("runtimes/unix/lib/netstandard1.5/a.dll", targetLib.RuntimeTargets[0].Path); Assert.Equal("runtime", targetLib.RuntimeTargets[0].Properties["assetType"]); Assert.Equal("unix", targetLib.RuntimeTargets[0].Properties["rid"]); Assert.Equal("runtimes/win7-x86/lib/netstandard1.5/en-us/a.resources.dll", targetLib.RuntimeTargets[3].Path); Assert.Equal("resource", targetLib.RuntimeTargets[3].Properties["assetType"]); Assert.Equal("win7-x86", targetLib.RuntimeTargets[3].Properties["rid"]); Assert.Equal("runtimes/unix/native/a.dll", targetLib.RuntimeTargets[1].Path); Assert.Equal("native", targetLib.RuntimeTargets[1].Properties["assetType"]); Assert.Equal("unix", targetLib.RuntimeTargets[1].Properties["rid"]); // This section does not exist for RID graphs Assert.Equal(0, ridTargetLib.RuntimeTargets.Count); } }
public async Task Project2ProjectInLockFile_CSProjToXProj() { // Arrange var sources = new List <PackageSource>(); var projectJson = @" { ""version"": ""1.0.0"", ""dependencies"": { }, ""frameworks"": { ""net45"": {} } }"; var project2Json = @" { ""version"": ""1.0.0-*"", ""description"": ""Proj2 Class Library"", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""net45"": { } } }"; using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); var project2 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project2")); project1.Create(); project2.Create(); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), projectJson); File.WriteAllText(Path.Combine(project2.FullName, "project.json"), project2Json); File.WriteAllText(Path.Combine(project1.FullName, "project1.csproj"), string.Empty); File.WriteAllText(Path.Combine(project2.FullName, "project2.xproj"), string.Empty); var specPath1 = Path.Combine(project1.FullName, "project.json"); var specPath2 = Path.Combine(project2.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(projectJson, "project1", specPath1); var spec2 = JsonPackageSpecReader.GetPackageSpec(project2Json, "project2", specPath2); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir, logger); request.ExternalProjects.Add(new ExternalProjectReference( "project1", spec1, Path.Combine(project1.FullName, "project1.xproj"), new string[] { "project2" })); request.ExternalProjects.Add(new ExternalProjectReference( "project2", spec2, Path.Combine(project2.FullName, "project2.xproj"), new string[] { })); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); var format = new LockFileFormat(); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var lockFile = format.Read(request.LockFilePath, logger); var project2Lib = lockFile.GetLibrary("project2", NuGetVersion.Parse("1.0.0")); var project2Target = lockFile.GetTarget(FrameworkConstants.CommonFrameworks.Net45, runtimeIdentifier: null) .Libraries .Where(lib => lib.Name == "project2") .Single(); // Assert Assert.True(result.Success); Assert.Equal(1, lockFile.Libraries.Count); Assert.Equal("project", project2Lib.Type); Assert.Equal("../project2/project.json", project2Lib.Path); Assert.Equal("../project2/project2.xproj", project2Lib.MSBuildProject); Assert.Equal(".NETFramework,Version=v4.5", project2Target.Framework); Assert.Equal(1, project2Target.CompileTimeAssemblies.Count); Assert.Equal("net45/project2.dll", project2Target.CompileTimeAssemblies.Single().Path); } }
public async Task DependencyTypeConstraint_TargetPackage() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""dependencies"": { ""packageA"": { ""version"": ""1.0.0"", ""target"": ""package"" } }, ""frameworks"": { ""net45"": { } } }"; var packageAProjectJson = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""net45"": { } } }"; var globalJson = @" { ""projects"": [ ""projects"" ] }"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var packagesDir = new DirectoryInfo(Path.Combine(workingDir, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(workingDir, "packageSource")); var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); var packageAProject = new DirectoryInfo(Path.Combine(workingDir, "projects", "packageA")); var packageAExternalProject = new DirectoryInfo(Path.Combine(workingDir, "external", "packageA")); packagesDir.Create(); packageSource.Create(); project1.Create(); packageAProject.Create(); packageAExternalProject.Create(); sources.Add(new PackageSource(packageSource.FullName)); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); File.WriteAllText(Path.Combine(packageAProject.FullName, "project.json"), packageAProjectJson); File.WriteAllText(Path.Combine(workingDir, "global.json"), globalJson); var project1ProjPath = Path.Combine(project1.FullName, "project1.xproj"); File.WriteAllText(project1ProjPath, string.Empty); File.WriteAllText(Path.Combine(packageAProject.FullName, "packageA.xproj"), string.Empty); var specPath1 = Path.Combine(project1.FullName, "project.json"); var specPath2 = Path.Combine(packageAProject.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var spec2 = JsonPackageSpecReader.GetPackageSpec(packageAProjectJson, "packageA", specPath2); var packageAPath = SimpleTestPackageUtility.CreateFullPackage( packageSource.FullName, "packageA", "1.0.0"); await GlobalFolderUtility.AddPackageToGlobalFolderAsync(packageAPath, packagesDir); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir.FullName, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); var lockFile = result.LockFile; await result.CommitAsync(logger, CancellationToken.None); var packageALib = lockFile.GetLibrary("packageA", NuGetVersion.Parse("1.0.0")); var packageATarget = lockFile.GetTarget( FrameworkConstants.CommonFrameworks.Net45, runtimeIdentifier: null) .Libraries .Single(lib => lib.Name == "packageA"); // Assert Assert.True(result.Success); Assert.Equal(LibraryType.Package, packageALib.Type); Assert.Equal(LibraryType.Package, packageATarget.Type); } }
public async Task Project2ProjectInLockFile_VerifyProjectsNoAddedForV1() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""dependencies"": { ""project2"": ""1.0.0-*"", }, ""frameworks"": { ""net45"": {} } }"; var project2Json = @" { ""version"": ""1.0.0"", ""dependencies"": { ""project3"": ""1.0.0-*"", }, ""frameworks"": { ""net45"": {} } }"; var project3Json = @" { ""version"": ""1.0.0"", ""dependencies"": { }, ""frameworks"": { ""net45"": {} } }"; var globalJson = @" { ""projects"": [ ""projects"" ] }"; using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); var project2 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project2")); var project3 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project3")); project1.Create(); project2.Create(); project3.Create(); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); File.WriteAllText(Path.Combine(project2.FullName, "project.json"), project2Json); File.WriteAllText(Path.Combine(project3.FullName, "project.json"), project3Json); File.WriteAllText(Path.Combine(workingDir, "global.json"), globalJson); File.WriteAllText(Path.Combine(project1.FullName, "project1.xproj"), string.Empty); File.WriteAllText(Path.Combine(project2.FullName, "project2.xproj"), string.Empty); File.WriteAllText(Path.Combine(project3.FullName, "project3.xproj"), string.Empty); var specPath1 = Path.Combine(project1.FullName, "project.json"); var spec = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var specPath2 = Path.Combine(project2.FullName, "project.json"); var specPath3 = Path.Combine(project3.FullName, "project.json"); var logger = new TestLogger(); var request = new RestoreRequest(spec, sources, packagesDir, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); request.LockFileVersion = 1; var format = new LockFileFormat(); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); var lockFile = format.Read(request.LockFilePath, logger); // Assert Assert.True(result.Success); Assert.Equal(0, lockFile.Libraries.Count); Assert.Equal(0, lockFile.Targets[0].Libraries.Count); // Verify round tripping for v1 with p2ps Assert.Equal(result.LockFile, lockFile); } }
public async Task Resources_AppearInLockFileWithAppropriateLocaleValue() { // Arrange var logger = new TestLogger(); var framework = "net46"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var repository = Path.Combine(workingDir, "repository"); Directory.CreateDirectory(repository); var projectDir = Path.Combine(workingDir, "project"); Directory.CreateDirectory(projectDir); var packagesDir = Path.Combine(workingDir, "packages"); Directory.CreateDirectory(packagesDir); var file = new FileInfo(Path.Combine(repository, "packageA.1.0.0.nupkg")); using (var zip = new ZipArchive(File.Create(file.FullName), ZipArchiveMode.Create)) { zip.AddEntry("lib/net46/MyPackage.dll", new byte[] { 0 }); zip.AddEntry("lib/net46/en-US/MyPackage.resources.dll", new byte[] { 0 }); zip.AddEntry("lib/net46/en-CA/MyPackage.resources.dll", new byte[] { 0 }); zip.AddEntry("lib/net46/fr-CA/MyPackage.resources.dll", new byte[] { 0 }); zip.AddEntry("packageA.nuspec", @"<?xml version=""1.0"" encoding=""utf-8""?> <package xmlns=""http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd""> <metadata> <id>packageA</id> <version>1.0.0</version> <title /> <contentFiles> <files include=""**/*.*"" copyToOutput=""TRUE"" flatten=""true"" /> </contentFiles> </metadata> </package>", Encoding.UTF8); } var sources = new List <PackageSource>(); sources.Add(new PackageSource(repository)); var configJson = JObject.Parse(@"{ ""dependencies"": { ""packageA"": ""1.0.0"" }, ""frameworks"": { ""_FRAMEWORK_"": {} } }".Replace("_FRAMEWORK_", framework)); var specPath = Path.Combine(projectDir, "TestProject", "project.json"); var spec = JsonPackageSpecReader.GetPackageSpec(configJson.ToString(), "TestProject", specPath); var request = new RestoreRequest(spec, sources, packagesDir, logger); request.LockFilePath = Path.Combine(projectDir, "project.lock.json"); var command = new RestoreCommand(request); // Act var result = await command.ExecuteAsync(); await result.CommitAsync(logger, CancellationToken.None); // Assert var target = result.LockFile.GetTarget(NuGetFramework.Parse(framework), null); var lib = target.Libraries.Single(); var resourceAssemblies = lib.ResourceAssemblies; AssertResourceAssembly(resourceAssemblies, "lib/net46/en-US/MyPackage.resources.dll", "en-US"); AssertResourceAssembly(resourceAssemblies, "lib/net46/en-CA/MyPackage.resources.dll", "en-CA"); AssertResourceAssembly(resourceAssemblies, "lib/net46/fr-CA/MyPackage.resources.dll", "fr-CA"); } }
public async Task DependencyTypeConstraint_PackagesDependOnProject() { // Arrange var sources = new List <PackageSource>(); var project1Json = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""dependencies"": { ""packageA"": ""1.0.0"" }, ""frameworks"": { ""net45"": { } } }"; var packageBProjectJson = @" { ""version"": ""1.0.0"", ""description"": """", ""authors"": [ ""author"" ], ""tags"": [ """" ], ""projectUrl"": """", ""licenseUrl"": """", ""frameworks"": { ""net45"": { } } }"; var globalJson = @" { ""projects"": [ ""projects"" ] }"; using (var workingDir = TestFileSystemUtility.CreateRandomTestFolder()) { var packagesDir = new DirectoryInfo(Path.Combine(workingDir, "globalPackages")); var packageSource = new DirectoryInfo(Path.Combine(workingDir, "packageSource")); var project1 = new DirectoryInfo(Path.Combine(workingDir, "projects", "project1")); var packageBProject = new DirectoryInfo(Path.Combine(workingDir, "projects", "packageB")); packagesDir.Create(); packageSource.Create(); project1.Create(); packageBProject.Create(); sources.Add(new PackageSource(packageSource.FullName)); File.WriteAllText(Path.Combine(project1.FullName, "project.json"), project1Json); File.WriteAllText(Path.Combine(packageBProject.FullName, "project.json"), packageBProjectJson); File.WriteAllText(Path.Combine(workingDir, "global.json"), globalJson); var specPath1 = Path.Combine(project1.FullName, "project.json"); var specPath2 = Path.Combine(packageBProject.FullName, "project.json"); var spec1 = JsonPackageSpecReader.GetPackageSpec(project1Json, "project1", specPath1); var spec2 = JsonPackageSpecReader.GetPackageSpec(packageBProjectJson, "packageB", specPath2); var packageAPath = SimpleTestPackageUtility.CreateFullPackage( packageSource.FullName, "packageA", "1.0.0", new Packaging.Core.PackageDependency[] { new Packaging.Core.PackageDependency("packageB", VersionRange.Parse("1.0.0")) }); await GlobalFolderUtility.AddPackageToGlobalFolderAsync(packageAPath, packagesDir); var logger = new TestLogger(); var request = new RestoreRequest(spec1, sources, packagesDir.FullName, logger); request.LockFilePath = Path.Combine(project1.FullName, "project.lock.json"); // Act var command = new RestoreCommand(request); var result = await command.ExecuteAsync(); var lockFile = result.LockFile; await result.CommitAsync(logger, CancellationToken.None); // Assert Assert.True(result.Success); var packageBLib = lockFile.GetLibrary("packageB", NuGetVersion.Parse("1.0.0")); Assert.NotNull(packageBLib); Assert.Equal(LibraryType.Project, packageBLib.Type); } }