private static ProjectRestoreMetadata CreateRestoreMetadata(RestoreParams restoreParameters) { var metadata = new ProjectRestoreMetadata { ProjectUniqueName = restoreParameters.ProjectName, ProjectName = restoreParameters.ProjectName, ProjectStyle = ProjectStyle.PackageReference, ProjectPath = restoreParameters.ProjectName, OutputPath = restoreParameters.OutputPath, PackagesPath = restoreParameters.PackagesPath, ValidateRuntimeAssets = false, OriginalTargetFrameworks = { restoreParameters.TargetFramework.GetShortFolderName() } }; foreach (var configPath in restoreParameters.ConfigFilePaths) { metadata.ConfigFilePaths.Add(configPath); } foreach (var source in restoreParameters.Sources) { metadata.Sources.Add(source); } return(metadata); }
private static TargetFrameworkInformation CreateTargetFramework(RestoreParams restoreParameters) { var targetFramework = new TargetFrameworkInformation { FrameworkName = restoreParameters.TargetFramework }; if (restoreParameters.TargetFramework.Framework == ".NETCoreApp") { // targetFramework.Dependencies.Add(new LibraryDependency( // libraryRange: new LibraryRange("Microsoft.NETCore.App", // new VersionRange(restoreParameters.FrameworkVersion != null // ? new NuGetVersion(restoreParameters.FrameworkVersion) // : new NuGetVersion(restoreParameters.TargetFramework.Version)), LibraryDependencyTarget.Package), // type: LibraryDependencyType.Platform, // includeType: LibraryIncludeFlags.All, // suppressParent: LibraryIncludeFlags.All, // noWarn: Array.Empty<NuGetLogCode>(), // autoReferenced: true, // generatePathProperty:true)); } if (restoreParameters.Libraries != null) { foreach (var package in restoreParameters.Libraries) { AddPackageToFramework(targetFramework, package); } } return(targetFramework); }
internal RestoreParams CreateRestoreParams() { _initializationException?.Throw(); var restoreParams = new RestoreParams(); foreach (var packageSource in _packageSources) { restoreParams.Sources.Add(packageSource); } foreach (var configFile in _configFilePaths) { restoreParams.ConfigFilePaths.Add(configFile); } restoreParams.PackagesPath = PackageFolder; return(restoreParams); }
internal static async Task <RestoreResult> RestoreAsync(RestoreParams restoreParameters, ILogger logger, CancellationToken cancellationToken = default) { var providerCache = new RestoreCommandProvidersCache(); using var cacheContext = new SourceCacheContext { NoCache = false, IgnoreFailedSources = true }; var providers = new List <IPreLoadedRestoreRequestProvider>(); var dgSpec = new DependencyGraphSpec(); dgSpec.AddRestore(restoreParameters.ProjectName); var projectSpec = new PackageSpec { Name = restoreParameters.ProjectName, FilePath = restoreParameters.ProjectName, RestoreMetadata = CreateRestoreMetadata(restoreParameters), TargetFrameworks = { CreateTargetFramework(restoreParameters) } }; dgSpec.AddProject(projectSpec); providers.Add(new DependencyGraphSpecRequestProvider(providerCache, dgSpec)); var restoreContext = new RestoreArgs { CacheContext = cacheContext, LockFileVersion = LockFileFormat.Version, DisableParallel = false, Log = logger, MachineWideSettings = new XPlatMachineWideSetting(), PreLoadedRequestProviders = providers, AllowNoOp = true, HideWarningsAndErrors = true }; var restoreSummaries = await RestoreRunner.RunAsync(restoreContext, cancellationToken).ConfigureAwait(false); var result = new RestoreResult( success: restoreSummaries.All(x => x.Success), noOp: restoreSummaries.All(x => x.NoOpRestore), errors: restoreSummaries.SelectMany(x => x.Errors).Select(x => x.Message).ToImmutableArray()); return(result); }