public override async Task Implement(SharedState sharedState, CancellationToken cancellationToken)
        {
            await base.Implement(sharedState, cancellationToken);

            ReportStatus($"Installing Workload: {Workload.Id}...");

            var workloadManager = new DotNetWorkloadManager(SdkRoot, SdkVersion, NuGetPackageSources);

            if (NuGetVersion.TryParse(Workload.Version, out var version))
            {
                // Manually download and install the manifest to get an explicit version of it to install
                // we have to run `dotnet workload install <id> --skip-manifest-update` to make this happen
                if (await workloadManager.InstallWorkloadManifest(Workload.PackageId, Workload.Id, version, cancellationToken))
                {
                    // This runs the `dotnet workload install <id> --skip-manifest-update`
                    await workloadManager.CliInstall(Workload.Id);

                    // Find any template packs that the workload comes with
                    // we want to try and `dotnet new --uninstall` them
                    // Since if one was previously installed with `dotnet new -i` it will be chosen over the optional workload
                    // version and the user could get a message about a newer template being available to install
                    var templatePacks = workloadManager.GetPacksInWorkload(Workload.Id)?.Where(p => p.Kind == Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadPackKind.Template);

                    if (templatePacks?.Any() ?? false)
                    {
                        ReportStatus("Uninstalling previous template versions...");

                        foreach (var tp in templatePacks)
                        {
                            try { await workloadManager.UninstallTemplate(tp.Id); }
                            catch { }
                        }
                    }
                }

                // Install: dotnet workload install id --
                ReportStatus($"Installed Workload: {Workload.Id}.");
            }
            else
            {
                var msg = $"Failed to install workload: {Workload.Id}.";
                ReportStatus(msg);
                throw new System.Exception(msg);
            }
        }
        public override async Task Implement(SharedState sharedState, CancellationToken cancellationToken)
        {
            await base.Implement(sharedState, cancellationToken);

            ReportStatus($"Installing Workload: {Workload.Id}...");

            var workloadManager = new DotNetWorkloadManager(SdkRoot, SdkVersion, NuGetPackageSources);

            if (NuGetVersion.TryParse(Workload.Version, out var version) &&
                await workloadManager.InstallWorkloadManifest(Workload.PackageId, version, cancellationToken))
            {
                ReportStatus($"Installed Workload: {Workload.Id}.");
            }
            else
            {
                ReportStatus($"Failed to install workload: {Workload.Id}.");
            }
        }
Beispiel #3
0
        public override async Task Cure(CancellationToken cancellationToken)
        {
            await base.Cure(cancellationToken);

            foreach (var pack in Packages)
            {
                ReportStatus($"Installing Workload: {pack.Id}...");

                if (NuGetVersion.TryParse(pack.Version, out var version) &&
                    await WorkloadManager.InstallWorkloadManifest(pack.PackageId, version, cancellationToken))
                {
                    ReportStatus($"Installed Workload: {pack.Id}.");
                }
                else
                {
                    ReportStatus($"Failed to install workload: {pack.Id}.");
                }
            }
        }