Lots of minor cleanup and simplification.

This commit is contained in:
Michael Yanni 2023-11-10 17:50:52 -08:00
parent c42fb4c641
commit b25079d9e6
12 changed files with 56 additions and 135 deletions

View file

@ -62,20 +62,20 @@ namespace Microsoft.DotNet.Cli.Build
BundledTemplatesWithInstallPaths = BundledTemplates.Select(t => BundledTemplatesWithInstallPaths = BundledTemplates.Select(t =>
{ {
var templateWithInstallPath = new TaskItem(t); var templateWithInstallPath = new TaskItem(t);
templateWithInstallPath.SetMetadata("BundledTemplateInstallPath", groups[t.GetMetadata("TemplateFrameworkVersion")].BundledTemplateInstallPath); templateWithInstallPath.SetMetadata("BundledTemplateInstallPath", groups[t.GetMetadata("TemplateFrameworkVersion")].InstallPath);
return templateWithInstallPath; return templateWithInstallPath;
}).ToArray(); }).ToArray();
TemplatesComponents = groups.Select(g => TemplatesComponents = groups.Select(g =>
{ {
string majorMinorWithoutDots = g.Value.BundledTemplateMajorMinorVersion.Replace(".", ""); string majorMinorWithoutDots = g.Value.MajorMinorVersion.Replace(".", "");
var componentItem = new TaskItem($"NetCore{majorMinorWithoutDots}Templates"); var componentItem = new TaskItem($"NetCore{majorMinorWithoutDots}Templates");
var templateBaseFilename = $"dotnet-{majorMinorWithoutDots}templates"; var templateBaseFilename = $"dotnet-{majorMinorWithoutDots}templates";
componentItem.SetMetadata("TemplateBaseFilename", templateBaseFilename); componentItem.SetMetadata("TemplateBaseFilename", templateBaseFilename);
componentItem.SetMetadata("TemplatesMajorMinorVersion", g.Value.BundledTemplateMajorMinorVersion); componentItem.SetMetadata("TemplatesMajorMinorVersion", g.Value.MajorMinorVersion);
var installerUpgradeCode = GenerateGuidFromName.GenerateGuid(string.Join("-", templateBaseFilename, FullNugetVersion, ProductMonikerRid) + InstallerExtension).ToString().ToUpper(); var installerUpgradeCode = GenerateGuidFromName.GenerateGuid(string.Join("-", templateBaseFilename, FullNugetVersion, ProductMonikerRid) + InstallerExtension).ToString().ToUpper();
componentItem.SetMetadata("InstallerUpgradeCode", installerUpgradeCode); componentItem.SetMetadata("InstallerUpgradeCode", installerUpgradeCode);
componentItem.SetMetadata("MSIVersion", GenerateMsiVersionFromFullVersion.GenerateMsiVersion(CombinedBuildNumberAndRevision, g.Value.BundledTemplateMajorMinorPatchVersion)); componentItem.SetMetadata("MSIVersion", GenerateMsiVersionFromFullVersion.GenerateMsiVersion(CombinedBuildNumberAndRevision, g.Value.MajorMinorPatchVersion));
var brandName = System.Version.Parse(g.Key).Major >= 5 ? var brandName = System.Version.Parse(g.Key).Major >= 5 ?
$"Microsoft .NET {g.Key} Templates" : $"Microsoft .NET {g.Key} Templates" :
@ -89,24 +89,20 @@ namespace Microsoft.DotNet.Cli.Build
return true; return true;
} }
public static public static BundledTemplate Calculate(string aspNetCorePackageVersionTemplate)
(string BundledTemplateInstallPath,
string BundledTemplateMajorMinorVersion,
string BundledTemplateMajorMinorPatchVersion)
Calculate(string aspNetCorePackageVersionTemplate)
{ {
var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate); var aspNetCoreTemplate = NuGetVersion.Parse(aspNetCorePackageVersionTemplate);
NuGetVersion baseMajorMinorPatch = GetBaseMajorMinorPatch(aspNetCoreTemplate); NuGetVersion baseMajorMinorPatch = GetBaseMajorMinorPatch(aspNetCoreTemplate);
string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease string bundledTemplateInstallPath = aspNetCoreTemplate.IsPrerelease
? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{aspNetCoreTemplate.Release}" ? $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}-{aspNetCoreTemplate.Release}"
: $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}"; : $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}";
return ( return new BundledTemplate
bundledTemplateInstallPath, {
$"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}", InstallPath = bundledTemplateInstallPath,
$"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}"); MajorMinorVersion = $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}",
MajorMinorPatchVersion = $"{baseMajorMinorPatch.Major}.{baseMajorMinorPatch.Minor}.{baseMajorMinorPatch.Patch}"
};
} }
private static NuGetVersion GetBaseMajorMinorPatch(NuGetVersion aspNetCoreTemplate) private static NuGetVersion GetBaseMajorMinorPatch(NuGetVersion aspNetCoreTemplate)
@ -127,4 +123,11 @@ namespace Microsoft.DotNet.Cli.Build
return baseMajorMinorPatch; return baseMajorMinorPatch;
} }
} }
public record BundledTemplate
{
public string InstallPath { get; set; }
public string MajorMinorVersion { get; set; }
public string MajorMinorPatchVersion { get; set; }
}
} }

View file

@ -28,14 +28,6 @@ namespace Microsoft.DotNet.Cli.Build
private string GetMode() => Mode; private string GetMode() => Mode;
private string GetRecursive() private string GetRecursive() => Recursive ? "--recursive" : null;
{
if(Recursive)
{
return "--recursive";
}
return null;
}
} }
} }

View file

@ -1,13 +0,0 @@
// 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.Runtime.InteropServices;
namespace Microsoft.DotNet.Cli.Build.Framework
{
public static class Constants
{
//public static readonly string ProjectFileName = "project.json";
public static readonly string ExeSuffix = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty;
}
}

View file

@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
@ -63,11 +62,11 @@ namespace Microsoft.DotNet.Build.Tasks
if (toolResult) if (toolResult)
{ {
var files = Directory.GetFiles(Path.GetDirectoryName(TempOutputPath)); var files = Directory.GetFiles(Path.GetDirectoryName(TempOutputPath));
var dest = Path.GetDirectoryName(DestinationPath); var destination = Path.GetDirectoryName(DestinationPath);
// Copy both dll and pdb files to the destination folder // Copy both dll and pdb files to the destination folder
foreach(var file in files) foreach(var file in files)
{ {
File.Copy(file, Path.Combine(dest, Path.GetFileName(file)), overwrite: true); File.Copy(file, Path.Combine(destination, Path.GetFileName(file)), overwrite: true);
// Delete file in temp // Delete file in temp
File.Delete(file); File.Delete(file);
} }
@ -84,13 +83,11 @@ namespace Microsoft.DotNet.Build.Tasks
protected override string ToolName => "crossgen2"; protected override string ToolName => "crossgen2";
protected override MessageImportance StandardOutputLoggingImportance // Default is low, but we want to see output at normal verbosity.
// Default is low, but we want to see output at normal verbosity. protected override MessageImportance StandardOutputLoggingImportance => MessageImportance.Normal;
=> MessageImportance.Normal;
protected override MessageImportance StandardErrorLoggingImportance // This turns stderr messages into msbuild errors below.
// This turns stderr messages into msbuild errors below. protected override MessageImportance StandardErrorLoggingImportance => MessageImportance.High;
=> MessageImportance.High;
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance) protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance)
{ {
@ -116,35 +113,15 @@ namespace Microsoft.DotNet.Build.Tasks
} }
} }
protected override string GenerateFullPathToTool() protected override string GenerateFullPathToTool() => CrossgenPath ?? "crossgen2";
{
if (CrossgenPath != null)
{
return CrossgenPath;
}
return "crossgen2";
}
protected override string GenerateCommandLineCommands() => $"{GetInPath()} {GetOutPath()} {GetArchitecture()} {GetPlatformAssemblyPaths()} {GetCreateSymbols()}"; protected override string GenerateCommandLineCommands() => $"{GetInPath()} {GetOutPath()} {GetArchitecture()} {GetPlatformAssemblyPaths()} {GetCreateSymbols()}";
private string GetArchitecture() => $"--targetarch {Architecture}"; private string GetArchitecture() => $"--targetarch {Architecture}";
private string GetCreateSymbols() private string GetCreateSymbols() => RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "--pdb" : "--perfmap";
{
var option = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "--pdb" : "--perfmap";
return $"{option}";
}
private string GetReadyToRun() private string GetReadyToRun() => ReadyToRun ? "-readytorun" : null;
{
if (ReadyToRun)
{
return "-readytorun";
}
return null;
}
private string GetInPath() => $"\"{SourceAssembly}\""; private string GetInPath() => $"\"{SourceAssembly}\"";
@ -152,8 +129,7 @@ namespace Microsoft.DotNet.Build.Tasks
private string GetPlatformAssemblyPaths() private string GetPlatformAssemblyPaths()
{ {
var platformAssemblyPaths = String.Empty; var platformAssemblyPaths = string.Empty;
if (PlatformAssemblyPaths != null) if (PlatformAssemblyPaths != null)
{ {
foreach (var excludeTaskItem in PlatformAssemblyPaths) foreach (var excludeTaskItem in PlatformAssemblyPaths)

View file

@ -37,17 +37,15 @@ namespace Microsoft.DotNet.Cli.Build
protected override string GenerateFullPathToTool() protected override string GenerateFullPathToTool()
{ {
string path = ToolPath;
// if ToolPath was not provided by the MSBuild script // if ToolPath was not provided by the MSBuild script
if (string.IsNullOrEmpty(path)) if (string.IsNullOrEmpty(ToolPath))
{ {
Log.LogError($"Could not find the Path to {ToolName}"); Log.LogError($"Could not find the Path to {ToolName}");
return string.Empty; return string.Empty;
} }
return path; return ToolPath;
} }
protected override string GetWorkingDirectory() => WorkingDirectory ?? base.GetWorkingDirectory(); protected override string GetWorkingDirectory() => WorkingDirectory ?? base.GetWorkingDirectory();
@ -65,16 +63,9 @@ namespace Microsoft.DotNet.Cli.Build
protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance) => Log.LogMessage(messageImportance, singleLine, null); protected override void LogEventsFromTextOutput(string singleLine, MessageImportance messageImportance) => Log.LogMessage(messageImportance, singleLine, null);
protected override ProcessStartInfo GetProcessStartInfo( protected override ProcessStartInfo GetProcessStartInfo(string pathToTool, string commandLineCommands, string responseFileSwitch)
string pathToTool,
string commandLineCommands,
string responseFileSwitch)
{ {
var psi = base.GetProcessStartInfo( var psi = base.GetProcessStartInfo(pathToTool, commandLineCommands, responseFileSwitch);
pathToTool,
commandLineCommands,
responseFileSwitch);
foreach (var environmentVariableName in new EnvironmentFilter().GetEnvironmentVariableNamesToRemove()) foreach (var environmentVariableName in new EnvironmentFilter().GetEnvironmentVariableNamesToRemove())
{ {
psi.Environment.Remove(environmentVariableName); psi.Environment.Remove(environmentVariableName);

View file

@ -1,10 +1,9 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved. // 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. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
using Microsoft.DotNet.Cli.Build.Framework; using Microsoft.DotNet.Cli.Build.Framework;
namespace Microsoft.DotNet.Cli.Build namespace Microsoft.DotNet.Cli.Build
@ -19,16 +18,9 @@ namespace Microsoft.DotNet.Cli.Build
protected abstract string Args { get; } protected abstract string Args { get; }
protected override ProcessStartInfo GetProcessStartInfo( protected override ProcessStartInfo GetProcessStartInfo(string pathToTool, string commandLineCommands, string responseFileSwitch)
string pathToTool,
string commandLineCommands,
string responseFileSwitch)
{ {
var psi = base.GetProcessStartInfo( var psi = base.GetProcessStartInfo(pathToTool, commandLineCommands, responseFileSwitch);
pathToTool,
commandLineCommands,
responseFileSwitch);
foreach (var environmentVariableName in new EnvironmentFilter().GetEnvironmentVariableNamesToRemove()) foreach (var environmentVariableName in new EnvironmentFilter().GetEnvironmentVariableNamesToRemove())
{ {
psi.Environment.Remove(environmentVariableName); psi.Environment.Remove(environmentVariableName);
@ -39,23 +31,21 @@ namespace Microsoft.DotNet.Cli.Build
public string WorkingDirectory { get; set; } public string WorkingDirectory { get; set; }
protected override string ToolName => $"dotnet{Constants.ExeSuffix}"; protected override string ToolName => $"dotnet{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : string.Empty)}";
protected override MessageImportance StandardOutputLoggingImportance => MessageImportance.High; protected override MessageImportance StandardOutputLoggingImportance => MessageImportance.High;
protected override string GenerateFullPathToTool() protected override string GenerateFullPathToTool()
{ {
string path = ToolPath; // if ToolPath was not provided by the MSBuild script
if (string.IsNullOrEmpty(ToolPath))
// if ToolPath was not provided by the MSBuild script
if (string.IsNullOrEmpty(path))
{ {
Log.LogError($"Could not find the Path to {ToolName}"); Log.LogError($"Could not find the Path to {ToolName}");
return string.Empty; return string.Empty;
} }
return path; return ToolPath;
} }
protected override string GetWorkingDirectory() => WorkingDirectory ?? base.GetWorkingDirectory(); protected override string GetWorkingDirectory() => WorkingDirectory ?? base.GetWorkingDirectory();

View file

@ -47,13 +47,10 @@ namespace Microsoft.DotNet.Build.Tasks
var retVal = true; var retVal = true;
if (Directory.Exists(DestinationDirectory)) if (Directory.Exists(DestinationDirectory) && CleanDestination == true)
{ {
if (CleanDestination == true) Log.LogMessage(MessageImportance.Low, "'{0}' already exists, trying to delete before unzipping...", DestinationDirectory);
{ Directory.Delete(DestinationDirectory, recursive: true);
Log.LogMessage(MessageImportance.Low, "'{0}' already exists, trying to delete before unzipping...", DestinationDirectory);
Directory.Delete(DestinationDirectory, recursive: true);
}
} }
if (!File.Exists(SourceArchive)) if (!File.Exists(SourceArchive))
@ -178,16 +175,7 @@ namespace Microsoft.DotNet.Build.Tasks
return retVal; return retVal;
} }
private bool ShouldExtractItem(string path) private bool ShouldExtractItem(string path) => DirectoriesToCopy?.Any(p => path.StartsWith(p.ItemSpec)) ?? false;
{
if (DirectoriesToCopy != null)
{
return DirectoriesToCopy.Any(p => path.StartsWith(p.ItemSpec));
}
return false;
}
protected override string ToolName => "tar"; protected override string ToolName => "tar";

View file

@ -19,21 +19,14 @@ namespace Microsoft.DotNet.Cli.Build
{ {
if (NuGetVersion.TryParse(RuntimePackVersion, out var version)) if (NuGetVersion.TryParse(RuntimePackVersion, out var version))
{ {
if (version.IsPrerelease && version.Patch == 0) DefaultRuntimeFrameworkVersion = version.IsPrerelease && version.Patch == 0 ?
{ RuntimePackVersion :
DefaultRuntimeFrameworkVersion = RuntimePackVersion; new NuGetVersion(version.Major, version.Minor, 0).ToFullString();
}
else
{
DefaultRuntimeFrameworkVersion = new NuGetVersion(version.Major, version.Minor, 0).ToFullString();
}
return true; return true;
} }
else
{ return false;
return false;
}
} }
} }
} }

View file

@ -48,6 +48,7 @@ namespace Microsoft.DotNet.Cli.Build
{ {
Log.LogWarning($"GetComponentCommit failed for VersionDetailsXmlFile={VersionDetailsXmlFile}, DependencyName={DependencyName}: {ex}"); Log.LogWarning($"GetComponentCommit failed for VersionDetailsXmlFile={VersionDetailsXmlFile}, DependencyName={DependencyName}: {ex}");
} }
return true; return true;
} }
} }

View file

@ -24,6 +24,7 @@ namespace Microsoft.DotNet.Cli.Build
var runtimeJsonRoot = JObject.Parse(runtimeJsonContents); var runtimeJsonRoot = JObject.Parse(runtimeJsonContents);
string [] runtimeIdentifiers = ((JObject)runtimeJsonRoot["runtimes"]).Properties().Select(p => p.Name).ToArray(); string [] runtimeIdentifiers = ((JObject)runtimeJsonRoot["runtimes"]).Properties().Select(p => p.Name).ToArray();
AvailableRuntimePackRuntimeIdentifiers = runtimeIdentifiers.Select(rid => new TaskItem(rid)).ToArray(); AvailableRuntimePackRuntimeIdentifiers = runtimeIdentifiers.Select(rid => new TaskItem(rid)).ToArray();
return true; return true;
} }
} }

View file

@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information. // See the LICENSE file in the project root for more information.
using System;
using System.IO; using System.IO;
using Microsoft.Build.Framework; using Microsoft.Build.Framework;
using Microsoft.Build.Utilities; using Microsoft.Build.Utilities;
@ -118,7 +117,7 @@ namespace Microsoft.DotNet.Build.Tasks
private string GetExcludes() private string GetExcludes()
{ {
var excludes = String.Empty; var excludes = string.Empty;
if (ExcludePatterns != null) if (ExcludePatterns != null)
{ {

View file

@ -71,9 +71,9 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
private async Task<CommandResult> ExecuteAsyncInternal(string executable, string args) private async Task<CommandResult> ExecuteAsyncInternal(string executable, string args)
{ {
var stdOut = new List<String>(); var stdOut = new List<string>();
var stdErr = new List<String>(); var stdErr = new List<string>();
CurrentProcess = CreateProcess(executable, args); CurrentProcess = CreateProcess(executable, args);
@ -118,8 +118,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return new CommandResult( return new CommandResult(
CurrentProcess.StartInfo, CurrentProcess.StartInfo,
CurrentProcess.ExitCode, CurrentProcess.ExitCode,
String.Join(System.Environment.NewLine, stdOut), string.Join(System.Environment.NewLine, stdOut),
String.Join(System.Environment.NewLine, stdErr)); string.Join(System.Environment.NewLine, stdErr));
} }
private Process CreateProcess(string executable, string args) private Process CreateProcess(string executable, string args)