diff --git a/src/core-sdk-tasks/CalculateTemplateVersions.cs b/src/core-sdk-tasks/CalculateTemplateVersions.cs index ed392ed4a..97ccdfd14 100644 --- a/src/core-sdk-tasks/CalculateTemplateVersions.cs +++ b/src/core-sdk-tasks/CalculateTemplateVersions.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; +using System.Linq; using Microsoft.Build.Framework; using Microsoft.Build.Utilities; using NuGet.Versioning; @@ -9,26 +11,81 @@ namespace Microsoft.DotNet.Cli.Build { public class CalculateTemplateVersions : Task { + // Group BundledTemplates by TemplateFrameworkVersion + // In each group, get the version of the template with UseVersionForTemplateInstallPath=true + // From that version number, get the BundledTemplateInstallPath, BundledTemplateMajorMinorVersion, and BundledTemplateMajorMinorPatchVersion [Required] - public string AspNetCorePackageVersionTemplate { get; set; } + public ITaskItem [] BundledTemplates { get; set; } + + [Required] + public string FullNugetVersion { get; set; } + + [Required] + public string ProductMonikerRid { get; set; } + + [Required] + public string InstallerExtension { get; set; } + + [Required] + public int CombinedBuildNumberAndRevision { get; set; } + + + // Should be the BundledTemplates with BundledTemplateInstallPath metadata set to the value calculated for that group + [Output] + public ITaskItem [] BundledTemplatesWithInstallPaths { get; set; } + + // For each group of templates (grouped by TemplateFrameworkVersion), this should be the following + // ItemSpec: NetCore60Templates + // TemplateBaseFilename: dotnet-60templates + // TemplatesMajorMinorVersion: 6.0 (from BundledTemplateMajorMinorVersion from group) + // InstallerUpgradeCode: Guid generated using GenerateGuidFromName, combining TemplateBaseFilename, FullNugetVersion, ProductMonikerRid, and InstallerExtension + // MSIVersion: Result of calling GenerateMsiVersionFromFullVersion logic with CombinedBuildNumberAndRevision and BundledTemplateMajorMinorPatchVersion from template group [Output] - public string BundledTemplateInstallPath { get; set; } - - [Output] - public string BundledTemplateMajorMinorVersion { get; set; } - - [Output] - public string BundledTemplateMajorMinorPatchVersion { get; set; } + public ITaskItem [] TemplatesComponents { get; set; } private const int _patchVersionResetOffset = 1; public override bool Execute() { - var result = Calculate(AspNetCorePackageVersionTemplate); - BundledTemplateInstallPath = result.BundledTemplateInstallPath; - BundledTemplateMajorMinorVersion = result.BundledTemplateMajorMinorVersion; - BundledTemplateMajorMinorPatchVersion = result.BundledTemplateMajorMinorPatchVersion; + var groups = BundledTemplates.GroupBy(bt => bt.GetMetadata("TemplateFrameworkVersion")) + .ToDictionary(g => g.Key, g => + { + var itemWithVersion = g.SingleOrDefault(i => i.GetMetadata("UseVersionForTemplateInstallPath").Equals("true", StringComparison.OrdinalIgnoreCase)); + if (itemWithVersion == null) + { + throw new InvalidOperationException("Could not find single item with UseVersionForTemplateInstallPath for templates with TemplateFrameworkVersion: " + g.Key); + } + + return Calculate(itemWithVersion.GetMetadata("PackageVersion")); + }); + + BundledTemplatesWithInstallPaths = BundledTemplates.Select(t => + { + var templateWithInstallPath = new TaskItem(t); + templateWithInstallPath.SetMetadata("BundledTemplateInstallPath", groups[t.GetMetadata("TemplateFrameworkVersion")].BundledTemplateInstallPath); + return templateWithInstallPath; + }).ToArray(); + + TemplatesComponents = groups.Select(g => + { + string majorMinorWithoutDots = g.Value.BundledTemplateMajorMinorVersion.Replace(".", ""); + var componentItem = new TaskItem($"NetCore{majorMinorWithoutDots}Templates"); + var templateBaseFilename = $"dotnet-{majorMinorWithoutDots}templates"; + componentItem.SetMetadata("TemplateBaseFilename", templateBaseFilename); + componentItem.SetMetadata("TemplatesMajorMinorVersion", g.Value.BundledTemplateMajorMinorVersion); + var installerUpgradeCode = GenerateGuidFromName.GenerateGuid(string.Join("-", templateBaseFilename, FullNugetVersion, ProductMonikerRid) + InstallerExtension).ToString().ToUpper(); + componentItem.SetMetadata("InstallerUpgradeCode", installerUpgradeCode); + componentItem.SetMetadata("MSIVersion", GenerateMsiVersionFromFullVersion.GenerateMsiVersion(CombinedBuildNumberAndRevision, g.Value.BundledTemplateMajorMinorPatchVersion)); + + var brandName = System.Version.Parse(g.Key).Major >= 5 ? + $"Microsoft .NET {g.Key} Templates" : + $"Microsoft .NET Core {g.Key} Templates"; + + componentItem.SetMetadata("BrandNameWithoutVersion", brandName); + + return componentItem; + }).ToArray(); return true; } diff --git a/src/core-sdk-tasks/CollatePackageDownloads.cs b/src/core-sdk-tasks/CollatePackageDownloads.cs new file mode 100644 index 000000000..1e0c8ab9e --- /dev/null +++ b/src/core-sdk-tasks/CollatePackageDownloads.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; + +namespace Microsoft.DotNet.Cli.Build +{ + // Multiple PackageDownload items for the same package are not supported. Rather, to download multiple versions of the same + // package, the PackageDownload items can have a semicolon-separated list of versions (each in brackets) as the Version metadata. + // So this task groups a list of items with PackageVersion metadata into a list of items which can be used as PackageDownloads + public class CollatePackageDownloads : Task + { + [Required] + public ITaskItem[] Packages { get; set; } + + [Output] + public ITaskItem [] PackageDownloads { get; set; } + + public override bool Execute() + { + PackageDownloads = Packages.GroupBy(p => p.ItemSpec) + .Select(g => + { + var packageDownloadItem = new TaskItem(g.Key); + packageDownloadItem.SetMetadata("Version", string.Join(";", + g.Select(p => "[" + p.GetMetadata("PackageVersion") + "]"))); + return packageDownloadItem; + }).ToArray(); + + return true; + } + } +} diff --git a/src/core-sdk-tasks/GenerateMsiVersionFromFullVersion.cs b/src/core-sdk-tasks/GenerateMsiVersionFromFullVersion.cs index 12e85dd22..72307e4c1 100644 --- a/src/core-sdk-tasks/GenerateMsiVersionFromFullVersion.cs +++ b/src/core-sdk-tasks/GenerateMsiVersionFromFullVersion.cs @@ -20,19 +20,24 @@ namespace Microsoft.DotNet.Cli.Build public override bool Execute() { - var parsedVersion = NuGetVersion.Parse(VersionMajorMinorPatch); + MsiVersion = GenerateMsiVersion(VersionRevision, VersionMajorMinorPatch); + + return true; + } + + public static string GenerateMsiVersion(int versionRevision, string versionMajorMinorPatch) + { + var parsedVersion = NuGetVersion.Parse(versionMajorMinorPatch); var buildVersion = new Version() { Major = parsedVersion.Major, Minor = parsedVersion.Minor, Patch = parsedVersion.Patch, - VersionRevision = VersionRevision + VersionRevision = versionRevision }; - MsiVersion = buildVersion.GenerateMsiVersion(); - - return true; + return buildVersion.GenerateMsiVersion(); } } } diff --git a/src/redist/targets/Branding.targets b/src/redist/targets/Branding.targets index bfcdaaf34..6b6e2642b 100644 --- a/src/redist/targets/Branding.targets +++ b/src/redist/targets/Branding.targets @@ -13,10 +13,6 @@ Microsoft .NET Host FX Resolver $(HostFxrVersion) Microsoft.NETCore.App $(SharedFrameworkName) - Microsoft .NET Core 5.0 Templates $(Version) - Microsoft .NET Core 3.1 Templates $(Version) - Microsoft .NET Core 3.0 Templates $(Version) - Microsoft .NET Core 2.1 Templates $(Version) diff --git a/src/redist/targets/BuildCoreSdkTasks.targets b/src/redist/targets/BuildCoreSdkTasks.targets index 99bef9140..cf37a9f01 100644 --- a/src/redist/targets/BuildCoreSdkTasks.targets +++ b/src/redist/targets/BuildCoreSdkTasks.targets @@ -39,5 +39,6 @@ + diff --git a/src/redist/targets/BundledTemplates.targets b/src/redist/targets/BundledTemplates.targets index fc1983c3e..9849ccaf2 100644 --- a/src/redist/targets/BundledTemplates.targets +++ b/src/redist/targets/BundledTemplates.targets @@ -1,55 +1,23 @@ - - - - - - - - - - + + + - - - - - + + + $(ArtifactsNonShippingPackagesDir)%(TemplatesComponents.TemplateBaseFilename)-$(FullNugetVersion)-$(ProductMonikerRid)$(InstallerExtension) + + - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -67,12 +35,12 @@ - @@ -82,178 +50,119 @@ - + - + - + - + - + - + - + - + + + + + + + + + %(Identity)/%(PackageVersion)/%(Identity).%(PackageVersion).nupkg $(NuGetPackageRoot)$([MSBuild]::ValueOrDefault('%(NupkgPathRelativeToPackageRoot)', '').ToLower()) - [%(PackageVersion)] - + + + + + + + + + + + + $(TargetFramework) + - - %(Identity)/%(PackageVersion)/%(Identity).%(PackageVersion).nupkg - $(NuGetPackageRoot)$([MSBuild]::ValueOrDefault('%(NupkgPathRelativeToPackageRoot)', '').ToLower()) - [%(PackageVersion)] - - - - - %(Identity)/%(PackageVersion)/%(Identity).%(PackageVersion).nupkg - $(NuGetPackageRoot)$([MSBuild]::ValueOrDefault('%(NupkgPathRelativeToPackageRoot)', '').ToLower()) - [%(PackageVersion)] - - - - - %(Identity)/%(PackageVersion)/%(Identity).%(PackageVersion).nupkg - $(NuGetPackageRoot)$([MSBuild]::ValueOrDefault('%(NupkgPathRelativeToPackageRoot)', '').ToLower()) - [%(PackageVersion)] - - - - - %(Identity)/%(PackageVersion)/%(Identity).%(PackageVersion).nupkg - $(NuGetPackageRoot)$([MSBuild]::ValueOrDefault('%(NupkgPathRelativeToPackageRoot)', '').ToLower()) - [%(PackageVersion)] - + @(BundledTemplatePackageDownload->'', ' + ') + +]]> + + $(IntermediateOutputPath)TemplatePackageDownloader\ + $(TemplatePackageDownloadProjectDirectory)TemplatePackageDownloader.csproj + - - + + - - - - - + + - - - - - - - - - - - - + DependsOnTargets="LayoutTemplatesForSDK;LayoutTemplatesForMSI" /> + DependsOnTargets="SetupBundledComponents;CalculateTemplatesVersions;DownloadBundledTemplateNupkgs"> - - - - + + - + - + - - - - - - - - + + + - - - - - - - diff --git a/src/redist/targets/GenerateLayout.targets b/src/redist/targets/GenerateLayout.targets index 9541f33fe..a0a3a559e 100644 --- a/src/redist/targets/GenerateLayout.targets +++ b/src/redist/targets/GenerateLayout.targets @@ -2,10 +2,6 @@ $(BaseOutputPath)$(Configuration)\dotnet\ $(BaseOutputPath)$(Configuration)\dotnet-internal\ - $(BaseOutputPath)$(Configuration)\templates-5.0\ - $(BaseOutputPath)$(Configuration)\templates-3.1\ - $(BaseOutputPath)$(Configuration)\templates-3.0\ - $(BaseOutputPath)$(Configuration)\templates-2.1\ $(IntermediateOutputPath)downloads\ diff --git a/src/redist/targets/GenerateMSIs.targets b/src/redist/targets/GenerateMSIs.targets index 4b1875933..11f613060 100644 --- a/src/redist/targets/GenerateMSIs.targets +++ b/src/redist/targets/GenerateMSIs.targets @@ -59,10 +59,6 @@ $(ArtifactsNonShippingPackagesDir)$(ArtifactNameWithVersionSdk)$(InstallerExtension) Dotnet_CLI - $(ArtifactsNonShippingPackagesDir)dotnet-50templates-$(FullNugetVersion)-$(ProductMonikerRid)$(InstallerExtension) - $(ArtifactsNonShippingPackagesDir)dotnet-31templates-$(FullNugetVersion)-$(ProductMonikerRid)$(InstallerExtension) - $(ArtifactsNonShippingPackagesDir)dotnet-30templates-$(FullNugetVersion)-$(ProductMonikerRid)$(InstallerExtension) - $(ArtifactsNonShippingPackagesDir)dotnet-21templates-$(FullNugetVersion)-$(ProductMonikerRid)$(InstallerExtension) $(ArtifactsNonShippingPackagesDir)dotnet-sdkplaceholder-$(FullNugetVersion)-$(ProductMonikerRid)$(InstallerExtension) NetCore_SdkPlaceholder $(ArtifactsShippingPackagesDir)$(ArtifactNameWithVersionCombinedHostHostFxrFrameworkSdk)$(BundleExtension) @@ -100,10 +96,11 @@ + DependsOnTargets="GenerateLayout;SetupWixProperties;SetupTemplatesMsis"> - + + - - - - - - - - - - - - - - - - @@ -287,40 +264,12 @@ - - $(Templates50LayoutPath.TrimEnd('\')) - $(Templates50MSIInstallerFile) - $(BundledTemplates50BrandName) - $(BundledTemplates50MsiVersion) - $(Templates50InstallerUpgradeCode) - NetCore_Templates_5.0 - - - - - - $(Templates31LayoutPath.TrimEnd('\')) - $(Templates31MSIInstallerFile) - $(BundledTemplates31BrandName) - $(BundledTemplates31MsiVersion) - $(Templates31InstallerUpgradeCode) - NetCore_Templates_3.1 - - - $(Templates30LayoutPath.TrimEnd('\')) - $(Templates30MSIInstallerFile) - $(BundledTemplates30BrandName) - $(BundledTemplates30MsiVersion) - $(Templates30InstallerUpgradeCode) - NetCore_Templates_3.0 - - - $(Templates21LayoutPath.TrimEnd('\')) - $(Templates21MSIInstallerFile) - $(BundledTemplates21BrandName) - $(BundledTemplates21MsiVersion) - $(Templates21InstallerUpgradeCode) - NetCore_Templates_2.1 + + $(BaseOutputPath)$(Configuration)\templates-%(TemplatesComponents.TemplatesMajorMinorVersion) + %(TemplatesComponents.BrandNameWithoutVersion) $(Version) + %(TemplatesComponents.MSIVersion) + %(TemplatesComponents.InstallerUpgradeCode) + NetCore_Templates_%(TemplatesComponents.TemplatesMajorMinorVersion) @@ -334,6 +283,15 @@ $(DownloadedSharedHostInstallerFile); $(SdkGenerateBundlePowershellScript)" Outputs="$(CombinedFrameworkSdkHostMSIInstallerFile)"> + + + + + + + @(LatestTemplateInstallerComponent->'%(MSIInstallerFile)') + - $(Templates50MSIInstallerFile) - $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.NetCore.Templates.$(BundledTemplates50MajorMinorVersion).$(FullNugetVersion).nupkg - $(BundledTemplates50MajorMinorVersion) - - - $(Templates31MSIInstallerFile) - $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.NetCore.Templates.$(BundledTemplates31MajorMinorVersion).$(FullNugetVersion).nupkg - $(BundledTemplates31MajorMinorVersion) - - - $(Templates30MSIInstallerFile) - $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.NetCore.Templates.$(BundledTemplates30MajorMinorVersion).$(FullNugetVersion).nupkg - $(BundledTemplates30MajorMinorVersion) - - - $(Templates21MSIInstallerFile) - $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.NetCore.Templates.$(BundledTemplates21MajorMinorVersion).$(FullNugetVersion).nupkg - $(BundledTemplates21MajorMinorVersion) + + $(ArtifactsNonShippingPackagesDir)VS.Redist.Common.NetCore.Templates.%(TemplatesMajorMinorVersion).$(FullNugetVersion).nupkg + %(TemplatesMajorMinorVersion) + + DependsOnTargets="SetSignProps;SetupTemplatesMsis"> - + - - - - - - $(InternalCertificateId)