private static PackageSpec WithProjectJsonTestRestoreMetadata(this PackageSpec spec) { var updated = spec.Clone(); var metadata = new ProjectRestoreMetadata(); updated.RestoreMetadata = metadata; var msbuildProjectFilePath = Path.Combine(Path.GetDirectoryName(spec.FilePath), spec.Name + ".csproj"); var msbuildProjectExtensionsPath = Path.Combine(Path.GetDirectoryName(spec.FilePath), "obj"); metadata.ProjectStyle = ProjectStyle.ProjectJson; metadata.OutputPath = msbuildProjectExtensionsPath; metadata.ProjectPath = msbuildProjectFilePath; metadata.ProjectJsonPath = spec.FilePath; metadata.ProjectName = spec.Name; metadata.ProjectUniqueName = msbuildProjectFilePath; metadata.CacheFilePath = NoOpRestoreUtilities.GetProjectCacheFilePath(msbuildProjectExtensionsPath); metadata.ConfigFilePaths = new List <string>(); foreach (var framework in updated.TargetFrameworks) { metadata.TargetFrameworks.Add(new ProjectRestoreMetadataFrameworkInfo(framework.FrameworkName) { }); } return(updated); }
public static PackageSpec WithPackagesConfigRestoreMetadata(this PackageSpec spec) { var updated = spec.Clone(); var packageSpecFile = new FileInfo(spec.FilePath); var projectDir = packageSpecFile.Directory.FullName; var projectPath = Path.Combine(projectDir, spec.Name + ".csproj"); updated.FilePath = projectPath; updated.RestoreMetadata = new PackagesConfigProjectRestoreMetadata(); updated.RestoreMetadata.OutputPath = projectDir; updated.RestoreMetadata.ProjectStyle = ProjectStyle.PackagesConfig; updated.RestoreMetadata.ProjectName = spec.Name; updated.RestoreMetadata.ProjectUniqueName = projectPath; updated.RestoreMetadata.ProjectPath = projectPath; updated.RestoreMetadata.ConfigFilePaths = new List <string>(); (updated.RestoreMetadata as PackagesConfigProjectRestoreMetadata).PackagesConfigPath = Path.GetFullPath(Path.Combine(projectDir, "../packages")); foreach (var framework in updated.TargetFrameworks) { updated.RestoreMetadata.TargetFrameworks.Add(new ProjectRestoreMetadataFrameworkInfo(framework.FrameworkName)); } return(updated); }
public static PackageSpec WithTestProjectReference(this PackageSpec parent, PackageSpec child, LibraryIncludeFlags privateAssets, params NuGetFramework[] frameworks) { var spec = parent.Clone(); if (frameworks.Length == 0) { // Use all frameworks if none were given frameworks = spec.TargetFrameworks.Select(e => e.FrameworkName).ToArray(); } foreach (var framework in spec .RestoreMetadata .TargetFrameworks .Where(e => frameworks.Contains(e.FrameworkName))) { framework.ProjectReferences.Add(new ProjectRestoreReference() { ProjectUniqueName = child.RestoreMetadata.ProjectUniqueName, ProjectPath = child.RestoreMetadata.ProjectPath, PrivateAssets = privateAssets, }); } return(spec); }
/// <summary> /// Add fake PackageReference restore metadata. /// </summary> public static PackageSpec WithTestRestoreMetadata(this PackageSpec spec) { var updated = spec.Clone(); var packageSpecFile = new FileInfo(spec.FilePath); var projectDir = packageSpecFile.Directory.FullName; var projectPath = Path.Combine(projectDir, spec.Name + ".csproj"); updated.FilePath = projectPath; updated.RestoreMetadata = new ProjectRestoreMetadata(); updated.RestoreMetadata.CrossTargeting = updated.TargetFrameworks.Count > 0; updated.RestoreMetadata.OriginalTargetFrameworks = updated.TargetFrameworks.Select(e => e.FrameworkName.GetShortFolderName()).ToList(); updated.RestoreMetadata.OutputPath = projectDir; updated.RestoreMetadata.ProjectStyle = ProjectStyle.PackageReference; updated.RestoreMetadata.ProjectName = spec.Name; updated.RestoreMetadata.ProjectUniqueName = spec.Name; updated.RestoreMetadata.ProjectPath = projectPath; updated.RestoreMetadata.ConfigFilePaths = new List <string>(); foreach (var framework in updated.TargetFrameworks.Select(e => e.FrameworkName)) { updated.RestoreMetadata.TargetFrameworks.Add(new ProjectRestoreMetadataFrameworkInfo(framework)); } return(updated); }
public void Clone_WhenIsDefaultVersionVaries_ReturnsEqualClone(bool expectedResult) { var packageSpec = new PackageSpec(); packageSpec.IsDefaultVersion = expectedResult; Assert.Equal(expectedResult, packageSpec.IsDefaultVersion); PackageSpec clone = packageSpec.Clone(); Assert.Equal(expectedResult, packageSpec.IsDefaultVersion); Assert.Equal(expectedResult, clone.IsDefaultVersion); Assert.True(packageSpec.Equals(clone)); }
public InterpretersPackageNode(PythonProjectNode project, PackageSpec spec) : base(project, new VirtualProjectElement(project)) { ExcludeNodeFromScc = true; _package = spec.Clone(); _packageName = spec.FullSpec; if (spec.ExactVersion.IsEmpty) { _caption = spec.Name; _canUninstall = false; } else { _caption = string.Format("{0} ({1})", spec.Name, spec.ExactVersion); _canUninstall = !CannotUninstall.Contains(spec.Name); } }
private static async Task <RestoreResultPair> PreviewAddPackageReference(PackageReferenceArgs packageReferenceArgs, DependencyGraphSpec dgSpec, PackageSpec originalPackageSpec) { // Set user agent and connection settings. XPlatUtility.ConfigureProtocol(); var providerCache = new RestoreCommandProvidersCache(); using (var cacheContext = new SourceCacheContext()) { cacheContext.NoCache = false; cacheContext.IgnoreFailedSources = false; // Pre-loaded request provider containing the graph file var providers = new List <IPreLoadedRestoreRequestProvider>(); // Create a copy to avoid modifying the original spec which may be shared. var updatedPackageSpec = originalPackageSpec.Clone(); PackageSpecOperations.AddOrUpdateDependency(updatedPackageSpec, packageReferenceArgs.PackageDependency); providers.Add(new DependencyGraphSpecRequestProvider(providerCache, dgSpec)); var restoreContext = new RestoreArgs() { CacheContext = cacheContext, LockFileVersion = LockFileFormat.Version, Log = packageReferenceArgs.Logger, MachineWideSettings = new XPlatMachineWideSetting(), GlobalPackagesFolder = packageReferenceArgs.PackageDirectory, PreLoadedRequestProviders = providers, Sources = packageReferenceArgs.Sources?.ToList() }; // Generate Restore Requests. There will always be 1 request here since we are restoring for 1 project. var restoreRequests = await RestoreRunner.GetRequests(restoreContext); // Run restore without commit. This will always return 1 Result pair since we are restoring for 1 request. var restoreResult = await RestoreRunner.RunWithoutCommit(restoreRequests, restoreContext); return(restoreResult.Single()); } }
/// <summary> /// Add fake PackageReference restore metadata. /// This resembles the .NET Core based projects (<see cref="ProjectRestoreSettings"/>. /// </summary> public static PackageSpec WithTestRestoreMetadata(this PackageSpec spec) { var updated = spec.Clone(); var packageSpecFile = new FileInfo(spec.FilePath); var projectDir = (packageSpecFile.Attributes & FileAttributes.Directory) == FileAttributes.Directory && !spec.FilePath.EndsWith(".csproj") ? packageSpecFile.FullName : packageSpecFile.Directory.FullName; var projectPath = Path.Combine(projectDir, spec.Name + ".csproj"); updated.FilePath = projectPath; updated.RestoreMetadata = new ProjectRestoreMetadata(); updated.RestoreMetadata.CrossTargeting = updated.TargetFrameworks.Count > 1; updated.RestoreMetadata.OriginalTargetFrameworks = updated.TargetFrameworks.Select(e => e.FrameworkName.GetShortFolderName()).ToList(); updated.RestoreMetadata.OutputPath = projectDir; updated.RestoreMetadata.ProjectStyle = ProjectStyle.PackageReference; updated.RestoreMetadata.ProjectName = spec.Name; updated.RestoreMetadata.ProjectUniqueName = projectPath; updated.RestoreMetadata.ProjectPath = projectPath; updated.RestoreMetadata.ConfigFilePaths = new List <string>(); updated.RestoreMetadata.CentralPackageVersionsEnabled = spec.RestoreMetadata?.CentralPackageVersionsEnabled ?? false; updated.RestoreMetadata.CentralPackageTransitivePinningEnabled = spec.RestoreMetadata?.CentralPackageTransitivePinningEnabled ?? false; // Update the Target Alias. foreach (var framework in updated.TargetFrameworks) { if (string.IsNullOrEmpty(framework.TargetAlias)) { framework.TargetAlias = framework.FrameworkName.GetShortFolderName(); } } foreach (var framework in updated.TargetFrameworks) { updated.RestoreMetadata.TargetFrameworks.Add(new ProjectRestoreMetadataFrameworkInfo(framework.FrameworkName) { TargetAlias = framework.TargetAlias }); } return(updated); }
public void WithReplacedPackageSpecs_WithASinglePackageSpec_Succeeds() { // Arrange var packageSpecA = new PackageSpec { Title = "A", RestoreMetadata = new ProjectRestoreMetadata() { ProjectUniqueName = "a", CentralPackageVersionsEnabled = false } }; var packageSpecB = new PackageSpec { Title = "B", RestoreMetadata = new ProjectRestoreMetadata() { ProjectUniqueName = "BBB" } }; var packageSpecC = new PackageSpec { Title = "C", RestoreMetadata = new ProjectRestoreMetadata() { ProjectUniqueName = "CCC" } }; var dgSpec = new DependencyGraphSpec(); dgSpec.AddProject(packageSpecA); dgSpec.AddProject(packageSpecB); dgSpec.AddProject(packageSpecC); dgSpec.AddRestore(packageSpecA.RestoreMetadata.ProjectUniqueName); dgSpec.AddRestore(packageSpecB.RestoreMetadata.ProjectUniqueName); dgSpec.AddRestore(packageSpecC.RestoreMetadata.ProjectUniqueName); // Create an updated packageSpecA var updatedPackageA = packageSpecA.Clone(); updatedPackageA.RestoreMetadata.ConfigFilePaths.Add("/samplePath"); var newNugetPackageSpecs = new List <PackageSpec>() { updatedPackageA }; // Preconditions dgSpec.Projects.Should().HaveCount(3); dgSpec.Restore.Should().HaveCount(3); // Act var dgSpecWithReplacedPackageA = dgSpec.WithPackageSpecs(newNugetPackageSpecs); // Assert dgSpecWithReplacedPackageA.Projects.Should().HaveCount(3); dgSpecWithReplacedPackageA.Restore.Should().HaveCount(1); var packageSpecInAFromDgSpec = dgSpecWithReplacedPackageA.Projects.Single(e => e.Title.Equals("A")); packageSpecInAFromDgSpec.Should().Be(updatedPackageA); dgSpecWithReplacedPackageA.Restore.Single().Should().Be(updatedPackageA.RestoreMetadata.ProjectUniqueName); }