Skip to content
Permalink
Browse files

[NuGet] Upgrade to 4.9 and use RestoreRunner to have faster noop rest…

…ore on second run
  • Loading branch information
xen2 committed Nov 20, 2018
1 parent 784b9c9 commit 9b985d4f134670018726c689638edeb5c0c0fb65
@@ -289,7 +289,7 @@ public async Task<NugetLocalPackage> InstallPackage(string packageId, PackageVer
var projectContext = new EmptyNuGetProjectContext()
{
ActionType = NuGetActionType.Install,
PackageExtractionContext = new PackageExtractionContext(PackageSaveMode.Defaultv3, XmlDocFileSaveMode.Skip, NativeLogger, null, null),
PackageExtractionContext = new PackageExtractionContext(PackageSaveMode.Defaultv3, XmlDocFileSaveMode.Skip, null, NativeLogger),
};

ActivityCorrelationId.StartNew();
@@ -323,7 +323,7 @@ public async Task<NugetLocalPackage> InstallPackage(string packageId, PackageVer
context.IgnoreFailedSources = true;

var provider = RestoreCommandProviders.Create(installPath, new List<string>(), sourceRepositoryProvider.GetRepositories(), context, new LocalPackageFileCache(), NativeLogger);
var request = new RestoreRequest(spec, provider, context, NativeLogger)
var request = new RestoreRequest(spec, provider, context, null, NativeLogger)
{
//RequestedRuntimes = { "win7-d3d11" },
ProjectStyle = ProjectStyle.DotnetCliTool,
@@ -388,7 +388,7 @@ public async Task UninstallPackage(NugetPackage package, ProgressReport progress
var projectContext = new EmptyNuGetProjectContext()
{
ActionType = NuGetActionType.Uninstall,
PackageExtractionContext = new PackageExtractionContext(PackageSaveMode.Defaultv3, XmlDocFileSaveMode.Skip, NativeLogger, null, null),
PackageExtractionContext = new PackageExtractionContext(PackageSaveMode.Defaultv3, XmlDocFileSaveMode.Skip, null, NativeLogger),
};

// Simply delete the installed package and its .nupkg installed in it.
@@ -8,8 +8,8 @@
<XenkoAssemblyProcessorOptions>--auto-module-initializer --serialization</XenkoAssemblyProcessorOptions>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NuGet.Protocol" Version="4.8.0" />
<PackageReference Include="NuGet.PackageManagement" Version="4.8.0" />
<PackageReference Include="NuGet.Protocol" Version="4.9.0-rtm.5658" />
<PackageReference Include="NuGet.PackageManagement" Version="4.9.0-rtm.5658" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<Reference Include="System.Core" />
<Reference Include="System.ComponentModel.DataAnnotations" />
@@ -60,11 +60,11 @@ public static async Task<(RestoreRequest, RestoreResult)> Restore(ILogger logger
var installPath = SettingsUtility.GetGlobalPackagesFolder(settings);
var assemblies = new List<string>();

var specPath = Path.Combine("TestProject", "project.json");
var projectPath = Path.Combine("XenkoNugetResolver.json");
var spec = new PackageSpec()
{
Name = "TestProject", // make sure this package never collides with a dependency
FilePath = specPath,
Name = Path.GetFileNameWithoutExtension(projectPath), // make sure this package never collides with a dependency
FilePath = projectPath,
Dependencies = new List<LibraryDependency>()
{
new LibraryDependency
@@ -79,27 +79,53 @@ public static async Task<(RestoreRequest, RestoreResult)> Restore(ILogger logger
FrameworkName = NuGetFramework.Parse("net472"),
}
},
RestoreMetadata = new ProjectRestoreMetadata
{
ProjectPath = projectPath,
ProjectName = Path.GetFileNameWithoutExtension(projectPath),
ProjectStyle = ProjectStyle.PackageReference,
ProjectUniqueName = projectPath,
OutputPath = Path.Combine(Path.GetTempPath(), $"XenkoNugetResolver-{packageName}-{versionRange.MinVersion.ToString()}"),
OriginalTargetFrameworks = new[] { "net472" },
ConfigFilePaths = settings.GetConfigFilePaths(),
PackagesPath = SettingsUtility.GetGlobalPackagesFolder(settings),
Sources = SettingsUtility.GetEnabledSources(settings).ToList(),
FallbackFolders = SettingsUtility.GetFallbackPackageFolders(settings).ToList()
},
};

using (var context = new SourceCacheContext())
{
context.IgnoreFailedSources = true;

var provider = RestoreCommandProviders.Create(installPath, new List<string>(), sourceRepositoryProvider.GetRepositories(), context, new LocalPackageFileCache(), logger);
var request = new RestoreRequest(spec, provider, context, logger)
var dependencyGraphSpec = new DependencyGraphSpec();

dependencyGraphSpec.AddProject(spec);

dependencyGraphSpec.AddRestore(spec.RestoreMetadata.ProjectUniqueName);

IPreLoadedRestoreRequestProvider requestProvider = new DependencyGraphSpecRequestProvider(new RestoreCommandProvidersCache(), dependencyGraphSpec);

var restoreArgs = new RestoreArgs
{
LockFilePath = "project.lock.json",
//RequestedRuntimes = { "win7-d3d11" },
ProjectStyle = ProjectStyle.DotnetCliTool,
AllowNoOp = true,
CacheContext = context,
CachingSourceProvider = new CachingSourceProvider(new PackageSourceProvider(settings)),
Log = logger,
};

var command = new RestoreCommand(request);

// Act
var result = await command.ExecuteAsync();
await result.CommitAsync(logger, CancellationToken.None);
// Create requests from the arguments
var requests = requestProvider.CreateRequests(restoreArgs).Result;

return (request, result);
// Restore the packages
var results = await RestoreRunner.RunWithoutCommit(requests, restoreArgs);
// Commit results so that noop cache works next time
foreach (var result in results)
{
await result.Result.CommitAsync(logger, CancellationToken.None);
}
var mainResult = results.First();
return (mainResult.SummaryRequest.Request, mainResult.Result);
}
}
}

0 comments on commit 9b985d4

Please sign in to comment.
You can’t perform that action at this time.