Exemple #1
0
        protected override async Task <UpgradeStepApplyResult> ApplyImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.EntryPoints.Any())
            {
                return(new UpgradeStepApplyResult(UpgradeStepStatus.Complete, "Entrypoint already set."));
            }

            var selectedProject = await GetEntrypointAsync(context, token).ConfigureAwait(false);

            if (selectedProject is null)
            {
                return(new UpgradeStepApplyResult(UpgradeStepStatus.Failed, "No project was selected."));
            }
            else
            {
                context.EntryPoints = new[] { selectedProject };
                await _restorer.RestorePackagesAsync(context, selectedProject, token).ConfigureAwait(false);

                return(new UpgradeStepApplyResult(UpgradeStepStatus.Complete, $"Project {selectedProject.GetRoslynProject().Name} was selected."));
            }
        }
Exemple #2
0
        public async Task <IDependencyAnalysisState> AnalyzeAsync(IUpgradeContext context, IProject?projectRoot, IReadOnlyCollection <TargetFrameworkMoniker> targetframeworks, CancellationToken token)
        {
            if (projectRoot is null)
            {
                _logger.LogError("No project available");
                throw new ArgumentNullException(nameof(projectRoot));
            }

            await _packageRestorer.RestorePackagesAsync(context, projectRoot, token).ConfigureAwait(false);

            var analysisState = new DependencyAnalysisState(projectRoot, projectRoot.NuGetReferences, targetframeworks);

            // Iterate through all package references in the project file
            foreach (var analyzer in _packageAnalyzers)
            {
                _logger.LogDebug("Analyzing packages with {AnalyzerName}", analyzer.Name);

                try
                {
                    await analyzer.AnalyzeAsync(projectRoot, analysisState, token).ConfigureAwait(false);
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception e)
#pragma warning restore CA1031 // Do not catch general exception types
                {
                    _logger.LogCritical("Package analysis failed (analyzer {AnalyzerName}: {Message}", analyzer.Name, e.Message);
                    analysisState.IsValid = false;
                }
            }

            return(analysisState);
        }
        public async Task <UpgradeStepApplyResult> ApplyAsync(IUpgradeContext context, IProject project, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (project is null)
            {
                throw new ArgumentNullException(nameof(project));
            }

            var components = await project.GetComponentsAsync(token).ConfigureAwait(false);

            if (components.HasFlag(ProjectComponents.XamarinAndroid) || components.HasFlag(ProjectComponents.XamariniOS))
            {
                context.Properties.SetPropertyValue("componentFlag", components.ToString(), true);
            }

            var result = await RunTryConvertAsync(context, project, token).ConfigureAwait(false);

            await _restorer.RestorePackagesAsync(context, project, token).ConfigureAwait(false);

            return(result);
        }
Exemple #4
0
        private async Task <bool> PopulatePackageRestoreState(IUpgradeContext context, IPackageRestorer packageRestorer, CancellationToken token)
        {
            if (LockFilePath is null || PackageCachePath is null || Failed)
            {
                var restoreOutput = await packageRestorer.RestorePackagesAsync(context, context.CurrentProject.Required(), token).ConfigureAwait(false);

                if (restoreOutput.LockFilePath is null || restoreOutput.PackageCachePath is null)
                {
                    Failed = true;
                    return(false);
                }
        protected async override Task <UpgradeStepApplyResult> ApplyImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var result = await RunTryConvertAsync(context, context.CurrentProject.Required(), token).ConfigureAwait(false);

            await _restorer.RestorePackagesAsync(context, context.CurrentProject.Required(), token).ConfigureAwait(false);

            return(result);
        }
Exemple #6
0
        public async Task <IEnumerable <UpgradeStep> > InitializeAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.EntryPoint is not null)
            {
                await _restorer.RestorePackagesAsync(context, context.EntryPoint, token).ConfigureAwait(false);
            }

            return(AllSteps);
        }
        public async Task <IEnumerable <UpgradeStep> > InitializeAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (context.EntryPoint is not null)
            {
                await _restorer.RestorePackagesAsync(context, context.EntryPoint, token).ConfigureAwait(false);
            }

            if (!await RunChecksAsync(context, token).ConfigureAwait(false))
            {
                throw new UpgradeException("Readiness checks did not succeed. Please address any issues and try again.");
            }

            return(GetStepsForContext(context));
        }
        /// <summary>
        /// Creates a new analysis state object for a given upgrade context. This involves restoring packages for the context's current project.
        /// </summary>
        /// <param name="context">The upgrade context to create an analysis state for.</param>
        /// <param name="packageRestorer">The package restorer to use to restore packages for the context's project and generate a lock file.</param>
        /// <returns>A new PackageAnalysisState instance for the specified context.</returns>
        public static async Task <PackageAnalysisState> CreateAsync(IUpgradeContext context, IPackageRestorer packageRestorer, CancellationToken token)
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (packageRestorer is null)
            {
                throw new ArgumentNullException(nameof(packageRestorer));
            }

            if (context.CurrentProject is null)
            {
                throw new InvalidOperationException("Target TFM must be set before analyzing package references");
            }

            await packageRestorer.RestorePackagesAsync(context, context.CurrentProject.Required(), token).ConfigureAwait(false);

            return(new PackageAnalysisState());
        }
        protected override async Task <UpgradeStepApplyResult> ApplyImplAsync(IUpgradeContext context, CancellationToken token)
        {
            if (context is null)
            {
                throw new System.ArgumentNullException(nameof(context));
            }

            var project = context.CurrentProject.Required();

            var targetTfm = _tfmSelector.SelectTFM(project);
            var file      = project.GetFile();

            file.SetTFM(targetTfm);

            await file.SaveAsync(token).ConfigureAwait(false);

            // With an updated TFM, we should restore packages
            await _restorer.RestorePackagesAsync(context, context.CurrentProject.Required(), token).ConfigureAwait(false);

            return(new UpgradeStepApplyResult(UpgradeStepStatus.Complete, $"Updated TFM to {targetTfm}"));
        }