/// <summary> /// This is where the nominate calls for the IVs1 and IVS3 APIs combine. The reason for this method is to avoid duplication and potential issues /// The issue with this method is that it has some weird custom logging to ensure backward compatibility. It's on the implementer to ensure these calls are correct. /// <param name="projectUniqueName">projectUniqueName</param> /// <param name="projectRestoreInfo">projectRestoreInfo. Can be null</param> /// <param name="projectRestoreInfo2">proectRestoreInfo2. Can be null</param> /// <param name="token"></param> /// <remarks>Exactly one of projectRestoreInfos has to null.</remarks> /// <returns>The task that scheduled restore</returns> private Task <bool> NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, IVsProjectRestoreInfo2 projectRestoreInfo2, CancellationToken token) { if (string.IsNullOrEmpty(projectUniqueName)) { throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(projectUniqueName)); } if (projectRestoreInfo == null && projectRestoreInfo2 == null) { throw new ArgumentNullException(nameof(projectRestoreInfo)); } if (projectRestoreInfo != null && projectRestoreInfo2 != null) { throw new ArgumentException($"Internal error: Both {nameof(projectRestoreInfo)} and {nameof(projectRestoreInfo2)} cannot have values. Please file an issue at NuGet/Home if you see this exception."); } if (projectRestoreInfo != null) { if (projectRestoreInfo.TargetFrameworks == null) { throw new InvalidOperationException("TargetFrameworks cannot be null."); } } else { if (projectRestoreInfo2.TargetFrameworks == null) { throw new InvalidOperationException("TargetFrameworks cannot be null."); } } try { _logger.LogInformation( $"The nominate API is called for '{projectUniqueName}'."); var projectNames = ProjectNames.FromFullProjectPath(projectUniqueName); var dgSpec = ToDependencyGraphSpec(projectNames, projectRestoreInfo, projectRestoreInfo2); _projectSystemCache.AddProjectRestoreInfo(projectNames, dgSpec); // returned task completes when scheduled restore operation completes. var restoreTask = _restoreWorker.ScheduleRestoreAsync( SolutionRestoreRequest.OnUpdate(), token); return(restoreTask); } catch (OperationCanceledException) { throw; } catch (Exception e) { _logger.LogError(e.ToString()); return(Task.FromResult(false)); } }
private async Task <DependencyGraphSpec> CaptureNominateResultAsync( string projectFullPath, IVsProjectRestoreInfo pri) { DependencyGraphSpec capturedRestoreSpec = null; var cache = Mock.Of <IProjectSystemCache>(); Mock.Get(cache) .Setup(x => x.AddProjectRestoreInfo( It.IsAny <ProjectNames>(), It.IsAny <DependencyGraphSpec>())) .Callback <ProjectNames, DependencyGraphSpec>( (_, dg) => { capturedRestoreSpec = dg; }) .Returns(true); var restoreWorker = Mock.Of <ISolutionRestoreWorker>(); Mock.Get(restoreWorker) .Setup(x => x.ScheduleRestoreAsync( It.IsAny <SolutionRestoreRequest>(), CancellationToken.None)) .ReturnsAsync(true); var service = new VsSolutionRestoreService( cache, restoreWorker, NuGet.Common.NullLogger.Instance); // Act var result = await service.NominateProjectAsync(projectFullPath, pri, CancellationToken.None); Assert.True(result, "Project restore nomination should succeed."); return(capturedRestoreSpec); }
internal async Task OnRestoreInfoChangedAsync(IProjectVersionedValue <IVsProjectRestoreInfo> e) { // Restore service always does work regardless of whether the value we pass them to actually // contains changes, only nominate if there are any. if (RestoreComparer.RestoreInfos.Equals(_latestValue, e.Value)) { return; } // No configurations - likely during project close if (e.Value == null) { return; } _latestValue = e.Value; JoinableTask joinableTask = JoinableFactory.RunAsync(() => { return(NominateProjectRestoreAsync(e.Value, _projectAsynchronousTasksService.UnloadCancellationToken)); }); _projectAsynchronousTasksService.RegisterAsyncTask(joinableTask, ProjectCriticalOperation.Build | ProjectCriticalOperation.Unload | ProjectCriticalOperation.Rename, registerFaultHandler: true); // Prevent overlap until Restore completes await joinableTask; }
private static RuntimeGraph GetRuntimeGraph(IVsProjectRestoreInfo projectRestoreInfo) { var runtimes = projectRestoreInfo .TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .SelectMany(tfi => new[] { GetPropertyValueOrNull(tfi.Properties, RuntimeIdentifier), GetPropertyValueOrNull(tfi.Properties, RuntimeIdentifiers), }) .SelectMany(MSBuildStringUtility.Split) .Distinct(StringComparer.Ordinal) .Select(rid => new RuntimeDescription(rid)) .ToList(); var supports = projectRestoreInfo .TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .Select(tfi => GetPropertyValueOrNull(tfi.Properties, RuntimeSupports)) .SelectMany(MSBuildStringUtility.Split) .Distinct(StringComparer.Ordinal) .Select(s => new CompatibilityProfile(s)) .ToList(); return(new RuntimeGraph(runtimes, supports)); }
private Task ProjectPropertyChangedAsync(Tuple <ImmutableList <IProjectValueVersions>, TIdentityDictionary> sources) { IVsProjectRestoreInfo projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources.Item1, _projectVsServices.Project); if (projectRestoreInfo != null) { _projectVsServices.Project.Services.ProjectAsynchronousTasks .RegisterAsyncTask(JoinableFactory.RunAsync(async() => { LogProjectRestoreInfo(_projectVsServices.Project.FullPath, projectRestoreInfo); await _solutionRestoreService .NominateProjectAsync(_projectVsServices.Project.FullPath, projectRestoreInfo, _projectVsServices.Project.Services.ProjectAsynchronousTasks.UnloadCancellationToken) .ConfigureAwait(false); CodeMarkers.Instance.CodeMarker(CodeMarkerTimerId.PerfPackageRestoreEnd); CompleteLogProjectRestoreInfo(_projectVsServices.Project.FullPath); }), ProjectCriticalOperation.Build | ProjectCriticalOperation.Unload | ProjectCriticalOperation.Rename, registerFaultHandler: true); } return(Task.CompletedTask); }
public ProjectRestoreUpdate(ProjectConfiguration projectConfiguration, IVsProjectRestoreInfo restoreInfo) { Requires.NotNull(projectConfiguration, nameof(projectConfiguration)); Requires.NotNull(restoreInfo, nameof(restoreInfo)); ProjectConfiguration = projectConfiguration; RestoreInfo = restoreInfo; }
private async Task ProjectPropertyChangedAsync(Tuple <ImmutableList <IProjectValueVersions>, TIdentityDictionary> sources) { IVsProjectRestoreInfo projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources.Item1); if (projectRestoreInfo != null) { await _solutionRestoreService .NominateProjectAsync(_projectVsServices.Project.FullPath, projectRestoreInfo, CancellationToken.None) .ConfigureAwait(false); } }
private static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo) { var tfis = projectRestoreInfo .TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .Select(ToTargetFrameworkInformation) .ToArray(); var projectFullPath = Path.GetFullPath(projectNames.FullName); var projectDirectory = Path.GetDirectoryName(projectFullPath); // TODO: Remove temporary integration code NuGet/Home#3810 // Initialize OTF and CT values when original value of OTF property is not provided. var originalTargetFrameworks = tfis .Select(tfi => tfi.FrameworkName.GetShortFolderName()) .ToArray(); var crossTargeting = originalTargetFrameworks.Length > 1; // if "TargetFrameworks" property presents in the project file prefer the raw value. if (!string.IsNullOrWhiteSpace(projectRestoreInfo.OriginalTargetFrameworks)) { originalTargetFrameworks = MSBuildStringUtility.Split( projectRestoreInfo.OriginalTargetFrameworks); // cross-targeting is always ON even in case of a single tfm in the list. crossTargeting = true; } var packageSpec = new PackageSpec(tfis) { Name = GetPackageId(projectNames, projectRestoreInfo.TargetFrameworks), Version = GetPackageVersion(projectRestoreInfo.TargetFrameworks), FilePath = projectFullPath, RestoreMetadata = new ProjectRestoreMetadata { ProjectName = projectNames.ShortName, ProjectUniqueName = projectFullPath, ProjectPath = projectFullPath, OutputPath = Path.GetFullPath( Path.Combine( projectDirectory, projectRestoreInfo.BaseIntermediatePath)), ProjectStyle = ProjectStyle.PackageReference, TargetFrameworks = projectRestoreInfo.TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .Select(item => ToProjectRestoreMetadataFrameworkInfo(item, projectDirectory)) .ToList(), OriginalTargetFrameworks = originalTargetFrameworks, CrossTargeting = crossTargeting }, RuntimeGraph = GetRuntimeGraph(projectRestoreInfo) }; return(packageSpec); }
private async Task NominateProjectRestoreAsync(IVsProjectRestoreInfo restoreInfo, CancellationToken cancellationToken) { RestoreLogger.BeginNominateRestore(_logger, _project.FullPath, restoreInfo); // Nominate NuGet with the restore data. This will complete when we're guaranteed // that the assets files *at least* contains the changes that we pushed to it. await _solutionRestoreService.NominateProjectAsync(_project.FullPath, restoreInfo, cancellationToken); CodeMarkers.Instance.CodeMarker(CodeMarkerTimerId.PerfPackageRestoreEnd); RestoreLogger.EndNominateRestore(_logger, _project.FullPath); }
public async Task OnRestoreInfoChangedAsync_PushesRestoreInfoToRestoreService() { IVsProjectRestoreInfo result = null; var solutionRestoreService = IVsSolutionRestoreServiceFactory.ImplementNominateProjectAsync((projectFile, info, cancellationToken) => { result = info; }); var instance = await CreateInitializedInstance(solutionRestoreService : solutionRestoreService); var restoreInfo = IVsProjectRestoreInfoFactory.Create(); var value = IProjectVersionedValueFactory.Create(restoreInfo); await instance.OnRestoreInfoChangedAsync(value); Assert.Same(restoreInfo, result); }
private Task ProjectPropertyChangedAsync(Tuple <ImmutableList <IProjectValueVersions>, TIdentityDictionary> sources) { IVsProjectRestoreInfo projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources.Item1); if (projectRestoreInfo != null) { _projectVsServices.Project.Services.ProjectAsynchronousTasks .RegisterCriticalAsyncTask(JoinableFactory.RunAsync(() => _solutionRestoreService .NominateProjectAsync(_projectVsServices.Project.FullPath, projectRestoreInfo, CancellationToken.None)), registerFaultHandler: true); } return(Task.CompletedTask); }
public Task <bool> NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token) { if (string.IsNullOrEmpty(projectUniqueName)) { throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(projectUniqueName)); } if (projectRestoreInfo == null) { throw new ArgumentNullException(nameof(projectRestoreInfo)); } if (projectRestoreInfo.TargetFrameworks == null) { throw new InvalidOperationException("TargetFrameworks cannot be null."); } try { _logger.LogInformation( $"The nominate API is called for '{projectUniqueName}'."); var projectNames = ProjectNames.FromFullProjectPath(projectUniqueName); var dgSpec = ToDependencyGraphSpec(projectNames, projectRestoreInfo); #if DEBUG DumpProjectRestoreInfo(projectUniqueName, dgSpec); #endif _projectSystemCache.AddProjectRestoreInfo(projectNames, dgSpec); // returned task completes when scheduled restore operation completes. var restoreTask = _restoreWorker.ScheduleRestoreAsync( SolutionRestoreRequest.OnUpdate(), token); return(restoreTask); } catch (Exception e) when(e is InvalidOperationException || e is ArgumentException || e is FormatException) { _logger.LogError(e.ToString()); return(Task.FromResult(false)); } catch (Exception e) { _logger.LogError(e.ToString()); throw; } }
private Task ProjectPropertyChangedAsync(Tuple <ImmutableList <IProjectValueVersions>, TIdentityDictionary> sources) { IVsProjectRestoreInfo projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources.Item1, _projectVsServices.Project); if (projectRestoreInfo != null) { _projectVsServices.Project.Services.ProjectAsynchronousTasks .RegisterCriticalAsyncTask(JoinableFactory.RunAsync(async() => { await _solutionRestoreService .NominateProjectAsync(_projectVsServices.Project.FullPath, projectRestoreInfo, CancellationToken.None) .ConfigureAwait(false); Microsoft.Internal.Performance.CodeMarkers.Instance.CodeMarker(perfPackageRestoreEnd); }), registerFaultHandler: true); } return(Task.CompletedTask); }
private DependencyGraphSpec ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo) { var dgSpec = new DependencyGraphSpec(); var packageSpec = ToPackageSpec(projectNames, projectRestoreInfo); dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(packageSpec); if (projectRestoreInfo.ToolReferences != null) { var toolFramework = GetSingleNonEvaluatedPropertyOrNull( projectRestoreInfo.TargetFrameworks, ProjectBuildProperties.DotnetCliToolTargetFramework, NuGetFramework.Parse) ?? CommonFrameworks.NetCoreApp10; var packagesPath = GetRestoreProjectPath(projectRestoreInfo.TargetFrameworks); var fallbackFolders = GetRestoreFallbackFolders(projectRestoreInfo.TargetFrameworks).AsList(); var sources = GetRestoreSources(projectRestoreInfo.TargetFrameworks) .Select(e => new PackageSource(e)) .ToList(); projectRestoreInfo .ToolReferences .Cast <IVsReferenceItem>() .Select(r => ToolRestoreUtility.GetSpec( projectNames.FullName, r.Name, GetVersionRange(r), toolFramework, packagesPath, fallbackFolders, sources, projectWideWarningProperties: null)) .ForEach(ts => { dgSpec.AddRestore(ts.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(ts); }); } return(dgSpec); }
private void LogProjectRestoreInfo(string fullPath, IVsProjectRestoreInfo projectRestoreInfo) { if (_logger.IsEnabled) { using (IProjectLoggerBatch logger = _logger.BeginBatch()) { logger.WriteLine(); logger.WriteLine("------------------------------------------"); logger.WriteLine($"BEGIN Nominate Restore for {fullPath}"); logger.IndentLevel++; logger.WriteLine($"BaseIntermediatePath: {projectRestoreInfo.BaseIntermediatePath}"); logger.WriteLine($"OriginalTargetFrameworks: {projectRestoreInfo.OriginalTargetFrameworks}"); LogTargetFrameworks(logger, projectRestoreInfo.TargetFrameworks as TargetFrameworks); LogReferenceItems(logger, "Tool References", projectRestoreInfo.ToolReferences as ReferenceItems); logger.IndentLevel--; logger.WriteLine(); } } }
private void NominateProject(ImmutableList <IProjectValueVersions> sources) { IVsProjectRestoreInfo projectRestoreInfo = ProjectRestoreInfoBuilder.Build(sources, _projectVsServices.Project); if (projectRestoreInfo != null) { _projectVsServices.Project.Services.ProjectAsynchronousTasks .RegisterAsyncTask(JoinableFactory.RunAsync(async() => { LogProjectRestoreInfo(_projectVsServices.Project.FullPath, projectRestoreInfo); await _solutionRestoreService .NominateProjectAsync(_projectVsServices.Project.FullPath, projectRestoreInfo, _projectVsServices.Project.Services.ProjectAsynchronousTasks.UnloadCancellationToken); CodeMarkers.Instance.CodeMarker(CodeMarkerTimerId.PerfPackageRestoreEnd); CompleteLogProjectRestoreInfo(_projectVsServices.Project.FullPath); }), ProjectCriticalOperation.Build | ProjectCriticalOperation.Unload | ProjectCriticalOperation.Rename, registerFaultHandler: true); } }
private ProjectRestoreUpdate CreateRestoreUpdate(ProjectConfiguration projectConfiguration, IImmutableDictionary <string, IProjectRuleSnapshot> update) { IVsProjectRestoreInfo restoreInfo = RestoreBuilder.ToProjectRestoreInfo(update); return(new ProjectRestoreUpdate(projectConfiguration, restoreInfo)); }
private static DependencyGraphSpec ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo) { var dgSpec = new DependencyGraphSpec(); var packageSpec = ToPackageSpec(projectNames, projectRestoreInfo); dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(packageSpec); if (projectRestoreInfo.ToolReferences != null) { // Infer tool's TFM version from the current project TFM var projectTfms = projectRestoreInfo .TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .Select(tfi => NuGetFramework.Parse(tfi.TargetFrameworkMoniker)) .ToList(); var isNetCore20 = projectTfms .Where(tfm => tfm.Framework == FrameworkIdentifiers.NetCoreApp || tfm.Framework == FrameworkIdentifiers.NetStandard) .Any(tfm => tfm.Version >= Version20); var toolFramework = isNetCore20 ? CommonFrameworks.NetCoreApp20 : CommonFrameworks.NetCoreApp10; projectRestoreInfo .ToolReferences .Cast <IVsReferenceItem>() .Select(r => ToToolPackageSpec(projectNames, r, toolFramework)) .ToList() .ForEach(ts => { dgSpec.AddRestore(ts.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(ts); }); } return(dgSpec); }
private static DependencyGraphSpec ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo) { var dgSpec = new DependencyGraphSpec(); var packageSpec = ToPackageSpec(projectNames, projectRestoreInfo); dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(packageSpec); if (projectRestoreInfo.ToolReferences != null) { projectRestoreInfo .ToolReferences .Cast <IVsReferenceItem>() .Select(r => ToToolPackageSpec(projectNames, r)) .ToList() .ForEach(ts => { dgSpec.AddRestore(ts.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(ts); }); } return(dgSpec); }
private static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo) { var tfis = projectRestoreInfo .TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .Select(ToTargetFrameworkInformation) .ToArray(); var projectFullPath = Path.GetFullPath(projectNames.FullName); var projectDirectory = Path.GetDirectoryName(projectFullPath); // TODO: Remove temporary integration code NuGet/Home#3810 // Initialize OTF and CT values when original value of OTF property is not provided. var originalTargetFrameworks = tfis .Select(tfi => tfi.FrameworkName.GetShortFolderName()) .ToArray(); var crossTargeting = originalTargetFrameworks.Length > 1; // if "TargetFrameworks" property presents in the project file prefer the raw value. if (!string.IsNullOrWhiteSpace(projectRestoreInfo.OriginalTargetFrameworks)) { originalTargetFrameworks = MSBuildStringUtility.Split( projectRestoreInfo.OriginalTargetFrameworks); // cross-targeting is always ON even in case of a single tfm in the list. crossTargeting = true; } var outputPath = Path.GetFullPath( Path.Combine( projectDirectory, projectRestoreInfo.BaseIntermediatePath)); var projectName = GetPackageId(projectNames, projectRestoreInfo.TargetFrameworks); var packageSpec = new PackageSpec(tfis) { Name = projectName, Version = GetPackageVersion(projectRestoreInfo.TargetFrameworks), FilePath = projectFullPath, RestoreMetadata = new ProjectRestoreMetadata { ProjectName = projectName, ProjectUniqueName = projectFullPath, ProjectPath = projectFullPath, OutputPath = outputPath, ProjectStyle = ProjectStyle.PackageReference, TargetFrameworks = projectRestoreInfo.TargetFrameworks .Cast <IVsTargetFrameworkInfo>() .Select(item => ToProjectRestoreMetadataFrameworkInfo(item, projectDirectory)) .ToList(), OriginalTargetFrameworks = originalTargetFrameworks, CrossTargeting = crossTargeting, // Read project properties for settings. ISettings values will be applied later since // this value is put in the nomination cache and ISettings could change. PackagesPath = GetRestoreProjectPath(projectRestoreInfo.TargetFrameworks), FallbackFolders = GetRestoreFallbackFolders(projectRestoreInfo.TargetFrameworks).AsList(), Sources = GetRestoreSources(projectRestoreInfo.TargetFrameworks) .Select(e => new PackageSource(e)) .ToList(), ProjectWideWarningProperties = WarningProperties.GetWarningProperties( treatWarningsAsErrors: GetNonEvaluatedPropertyOrNull(projectRestoreInfo.TargetFrameworks, TreatWarningsAsErrors, e => e), warningsAsErrors: GetNonEvaluatedPropertyOrNull(projectRestoreInfo.TargetFrameworks, WarningsAsErrors, e => e), noWarn: GetNonEvaluatedPropertyOrNull(projectRestoreInfo.TargetFrameworks, NoWarn, e => e)), CacheFilePath = NoOpRestoreUtilities.GetProjectCacheFilePath(cacheRoot: outputPath, projectPath: projectFullPath) }, RuntimeGraph = GetRuntimeGraph(projectRestoreInfo), RestoreSettings = new ProjectRestoreSettings() { HideWarningsAndErrors = true } }; return(packageSpec); }
public Task <bool> NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, CancellationToken token) { return(NominateProjectAsync(projectUniqueName, projectRestoreInfo, null, token)); }
/// <summary> /// This is where the nominate calls for the IVs1 and IVS3 APIs combine. The reason for this method is to avoid duplication and potential issues /// The issue with this method is that it has some weird custom logging to ensure backward compatibility. It's on the implementer to ensure these calls are correct. /// <param name="projectUniqueName">projectUniqueName</param> /// <param name="projectRestoreInfo">projectRestoreInfo. Can be null</param> /// <param name="projectRestoreInfo2">proectRestoreInfo2. Can be null</param> /// <param name="token"></param> /// <remarks>Exactly one of projectRestoreInfos has to null.</remarks> /// <returns>The task that scheduled restore</returns> private Task <bool> NominateProjectAsync(string projectUniqueName, IVsProjectRestoreInfo projectRestoreInfo, IVsProjectRestoreInfo2 projectRestoreInfo2, CancellationToken token) { if (string.IsNullOrEmpty(projectUniqueName)) { throw new ArgumentException(Resources.Argument_Cannot_Be_Null_Or_Empty, nameof(projectUniqueName)); } if (projectRestoreInfo == null && projectRestoreInfo2 == null) { throw new ArgumentNullException(nameof(projectRestoreInfo)); } if (projectRestoreInfo != null && projectRestoreInfo2 != null) { throw new ArgumentException($"Internal error: Both {nameof(projectRestoreInfo)} and {nameof(projectRestoreInfo2)} cannot have values. Please file an issue at NuGet/Home if you see this exception."); } if (projectRestoreInfo != null) { if (projectRestoreInfo.TargetFrameworks == null) { throw new InvalidOperationException("TargetFrameworks cannot be null."); } } else { if (projectRestoreInfo2.TargetFrameworks == null) { throw new InvalidOperationException("TargetFrameworks cannot be null."); } } try { _logger.LogInformation( $"The nominate API is called for '{projectUniqueName}'."); var projectNames = ProjectNames.FromFullProjectPath(projectUniqueName); DependencyGraphSpec dgSpec; IReadOnlyList <IAssetsLogMessage> nominationErrors = null; try { dgSpec = ToDependencyGraphSpec(projectNames, projectRestoreInfo, projectRestoreInfo2); } catch (Exception e) { var restoreLogMessage = RestoreLogMessage.CreateError(NuGetLogCode.NU1105, string.Format(Resources.NU1105, projectNames.ShortName, e.Message)); restoreLogMessage.LibraryId = projectUniqueName; nominationErrors = new List <IAssetsLogMessage>() { AssetsLogMessage.Create(restoreLogMessage) }; var projectDirectory = Path.GetDirectoryName(projectUniqueName); string projectIntermediatePath = projectRestoreInfo == null ? projectRestoreInfo2.BaseIntermediatePath : projectRestoreInfo.BaseIntermediatePath; var dgSpecOutputPath = GetProjectOutputPath(projectDirectory, projectIntermediatePath); dgSpec = CreateMinimalDependencyGraphSpec(projectUniqueName, dgSpecOutputPath); } _projectSystemCache.AddProjectRestoreInfo(projectNames, dgSpec, nominationErrors); // returned task completes when scheduled restore operation completes. var restoreTask = _restoreWorker.ScheduleRestoreAsync( SolutionRestoreRequest.OnUpdate(), token); return(restoreTask); } catch (OperationCanceledException) { throw; } catch (Exception e) { _logger.LogError(e.ToString()); TelemetryUtility.EmitException(nameof(VsSolutionRestoreService), nameof(NominateProjectAsync), e); return(Task.FromResult(false)); } }
private static DependencyGraphSpec ToDependencyGraphSpec(ProjectNames projectNames, IVsProjectRestoreInfo projectRestoreInfo, IVsProjectRestoreInfo2 projectRestoreInfo2) { var dgSpec = new DependencyGraphSpec(); var packageSpec = projectRestoreInfo != null? ToPackageSpec(projectNames, projectRestoreInfo.TargetFrameworks, projectRestoreInfo.OriginalTargetFrameworks, projectRestoreInfo.BaseIntermediatePath) : ToPackageSpec(projectNames, projectRestoreInfo2.TargetFrameworks, projectRestoreInfo2.OriginalTargetFrameworks, projectRestoreInfo2.BaseIntermediatePath); dgSpec.AddRestore(packageSpec.RestoreMetadata.ProjectUniqueName); dgSpec.AddProject(packageSpec); if (projectRestoreInfo != null && projectRestoreInfo.ToolReferences != null) { VSNominationUtilities.ProcessToolReferences(projectNames, projectRestoreInfo.TargetFrameworks, projectRestoreInfo.ToolReferences, dgSpec); } else if (projectRestoreInfo2 != null && projectRestoreInfo2.ToolReferences != null) { VSNominationUtilities.ProcessToolReferences(projectNames, projectRestoreInfo2.TargetFrameworks, projectRestoreInfo2.ToolReferences, dgSpec); } return(dgSpec); }
public static void BeginNominateRestore(IProjectLogger logger, string fullPath, IVsProjectRestoreInfo projectRestoreInfo) { if (logger.IsEnabled) { using (IProjectLoggerBatch batch = logger.BeginBatch()) { batch.WriteLine(); batch.WriteLine("------------------------------------------"); batch.WriteLine($"BEGIN Nominate Restore for {fullPath}"); batch.IndentLevel++; batch.WriteLine($"MSBuildProjectExtensionsPath: {projectRestoreInfo.BaseIntermediatePath}"); batch.WriteLine($"OriginalTargetFrameworks: {projectRestoreInfo.OriginalTargetFrameworks}"); LogTargetFrameworks(batch, projectRestoreInfo.TargetFrameworks); LogReferenceItems(batch, "Tool References", projectRestoreInfo.ToolReferences); batch.IndentLevel--; batch.WriteLine(); } } }