Skip to content
Merged
10 changes: 10 additions & 0 deletions src/Installer/Microsoft.Dotnet.Installation/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

[assembly: InternalsVisibleTo("dnup, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: InternalsVisibleTo("dnup.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IDotnetReleaseInfoProvider
{
IEnumerable<string> GetAvailableChannels();

ReleaseVersion GetLatestVersion(InstallComponent component, string channel);
ReleaseVersion? GetLatestVersion(InstallComponent component, string channel);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It might be better to fail if we can't find a release version - that would likely be cleaner than requiring invokers to use !. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is, the caller should probably check for a null return value and either throw an error or handle appropriately if there is one. It might be better to just throw in the implementation. I think we'll want to clean up a lot of the ReleaseManifestcode, probably we can consider when we do that.


// Get all versions in a channel - do we have a scenario for this?
//IEnumerable<ReleaseVersion> GetAllVersions(InstallComponent component, string channel);
Expand Down
22 changes: 22 additions & 0 deletions src/Installer/Microsoft.Dotnet.Installation/InstallerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dotnet.Installation.Internal;

namespace Microsoft.Dotnet.Installation;

public static class InstallerFactory
{
public static IDotnetInstaller CreateInstaller()
{
return new DotnetInstaller();
}

public static IDotnetReleaseInfoProvider CreateReleaseInfoProvider()
{
return new DotnetReleaseInfoProvider();
}
}
28 changes: 28 additions & 0 deletions src/Installer/Microsoft.Dotnet.Installation/InstallerUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Microsoft.Dotnet.Installation;

public static class InstallerUtilities
{
public static InstallArchitecture GetInstallArchitecture(System.Runtime.InteropServices.Architecture architecture)
{
return architecture switch
{
System.Runtime.InteropServices.Architecture.X86 => InstallArchitecture.x86,
System.Runtime.InteropServices.Architecture.X64 => InstallArchitecture.x64,
System.Runtime.InteropServices.Architecture.Arm64 => InstallArchitecture.arm64,
_ => throw new NotSupportedException($"Architecture {architecture} is not supported.")
};
}

public static InstallArchitecture GetDefaultInstallArchitecture()
{
return GetInstallArchitecture(RuntimeInformation.ProcessArchitecture);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
using System.Runtime.InteropServices;
using Microsoft.Deployment.DotNet.Releases;

namespace Microsoft.DotNet.Tools.Bootstrapper;
namespace Microsoft.Dotnet.Installation.Internal;

internal class ArchiveDotnetInstaller : IDotnetInstaller, IDisposable
internal class ArchiveDotnetExtractor : IDisposable
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about the name DotnetArchiveExtractor? It feels more consistent with other types like DotnetInstaller.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this name! Agree it's an improvement.

{
private readonly DotnetInstallRequest _request;
private readonly ReleaseVersion _resolvedVersion;
private readonly bool _noProgress;
private string scratchDownloadDirectory;
private string? _archivePath;

public ArchiveDotnetInstaller(DotnetInstallRequest request, ReleaseVersion resolvedVersion, bool noProgress = false)
public ArchiveDotnetExtractor(DotnetInstallRequest request, ReleaseVersion resolvedVersion, bool noProgress = false)
{
_request = request;
_resolvedVersion = resolvedVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Linq;
using System.Runtime.InteropServices;

namespace Microsoft.DotNet.Tools.Bootstrapper;
namespace Microsoft.Dotnet.Installation.Internal;

internal static class DnupUtilities
{
Expand All @@ -34,22 +34,6 @@ public static bool PathsEqual(string? a, string? b)
StringComparison.OrdinalIgnoreCase);
}

public static InstallArchitecture GetInstallArchitecture(System.Runtime.InteropServices.Architecture architecture)
{
return architecture switch
{
System.Runtime.InteropServices.Architecture.X86 => InstallArchitecture.x86,
System.Runtime.InteropServices.Architecture.X64 => InstallArchitecture.x64,
System.Runtime.InteropServices.Architecture.Arm64 => InstallArchitecture.arm64,
_ => throw new NotSupportedException($"Architecture {architecture} is not supported.")
};
}

public static InstallArchitecture GetDefaultInstallArchitecture()
{
return GetInstallArchitecture(RuntimeInformation.ProcessArchitecture);
}

public static void ForceReplaceFile(string sourcePath, string destPath)
{
File.Copy(sourcePath, destPath, overwrite: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@
using Microsoft.Deployment.DotNet.Releases;
using Microsoft.Dotnet.Installation;

namespace Microsoft.DotNet.Tools.Bootstrapper;
namespace Microsoft.Dotnet.Installation.Internal;

/// <summary>
/// Represents a .NET installation with a fully specified version.
/// The MuxerDirectory is the directory of the corresponding .NET host that has visibility into this .NET installation.
/// </summary>
public record DotnetInstall(
internal record DotnetInstall(
DotnetInstallRoot InstallRoot,
ReleaseVersion Version,
InstallComponent Component);

/// <summary>
/// Represents a request for a .NET installation with a channel version that will get resolved into a fully specified version.
/// </summary>
public record DotnetInstallRequest(
internal record DotnetInstallRequest(
DotnetInstallRoot InstallRoot,
UpdateChannel Channel,
InstallComponent Component,
InstallRequestOptions Options);

public record InstallRequestOptions()
internal record InstallRequestOptions()
{
// Include options such as the custom feed, manifest path, etc.
public string? ManifestPath { get; init; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.DotNet.Releases;
using Spectre.Console;

namespace Microsoft.Dotnet.Installation.Internal
{
internal class DotnetInstaller : IDotnetInstaller
{
public void Install(DotnetInstallRoot dotnetRoot, InstallComponent component, ReleaseVersion version)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: DotnetInstaller and DotnetReleaseInfoProvider have brank lines between the members.

{
var installRequest = new DotnetInstallRequest(dotnetRoot, new UpdateChannel(version.ToString()), component, new InstallRequestOptions());

using ArchiveDotnetExtractor installer = new(installRequest, version, noProgress: true);
installer.Prepare();
installer.Commit();
}
public void Uninstall(DotnetInstallRoot dotnetRoot, InstallComponent component, ReleaseVersion version) => throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.DotNet.Releases;

namespace Microsoft.Dotnet.Installation.Internal;

internal class DotnetReleaseInfoProvider : IDotnetReleaseInfoProvider
{
public IEnumerable<string> GetAvailableChannels() => throw new NotImplementedException();
public ReleaseVersion? GetLatestVersion(InstallComponent component, string channel)
{
var releaseManifest = new ReleaseManifest();
var release = releaseManifest.GetLatestVersionForChannel(new UpdateChannel(channel), component);

return release;
}
public SupportType GetSupportType(InstallComponent component, ReleaseVersion version) => throw new NotImplementedException();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System.Threading.Tasks;
using Microsoft.Deployment.DotNet.Releases;

namespace Microsoft.DotNet.Tools.Bootstrapper;
namespace Microsoft.Dotnet.Installation.Internal;

/// <summary>
/// Handles downloading and parsing .NET release manifests to find the correct installer/archive for a given installation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System;
using System.Threading;

namespace Microsoft.DotNet.Tools.Bootstrapper;
namespace Microsoft.Dotnet.Installation.Internal;

public class ScopedMutex : IDisposable
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Spectre.Console;

namespace Microsoft.DotNet.Tools.Bootstrapper
namespace Microsoft.Dotnet.Installation.Internal
{
public class SpectreDownloadProgressReporter : IProgress<DownloadProgress>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.DotNet.Releases;

namespace Microsoft.Dotnet.Installation.Internal;

internal class UpdateChannel
{
public string Name { get; set; }

public UpdateChannel(string name)
{
Name = name;
}

public bool IsFullySpecifiedVersion()
{
return ReleaseVersion.TryParse(Name, out _);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAotCompatible>true</IsAotCompatible>

<!-- Strong naming not needed on .NET Core -->
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Deployment.DotNet.Releases" />
<!-- TODO: Create logging / progress abstraction and remove this dipendency from the library -->
<PackageReference Include="Spectre.Console" />
</ItemGroup>

</Project>
1 change: 1 addition & 0 deletions src/Installer/dnup/ArchiveInstallationValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using System.Linq;
using Microsoft.Dotnet.Installation.Internal;

namespace Microsoft.DotNet.Tools.Bootstrapper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using System.Linq;
using System.Net.Http;
using System.Threading;
using Microsoft.Dotnet.Installation.Internal;
using Microsoft.DotNet.Tools.Bootstrapper.Commands.Sdk.Install;
using Spectre.Console;

using SpectreAnsiConsole = Spectre.Console.AnsiConsole;

namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Sdk.Install
{
internal class EnvironmentVariableMockDotnetInstaller : IBootstrapperController
internal class EnvironmentVariableMockDotnetInstaller : IDotnetInstallManager
{
public GlobalJsonInfo GetGlobalJsonInfo(string initialDirectory)
{
Expand All @@ -36,7 +37,7 @@ public string GetDefaultDotnetInstallPath()
return null;
}
var installPath = Environment.GetEnvironmentVariable("DOTNET_TESTHOOK_CURRENT_INSTALL_PATH") ?? GetDefaultDotnetInstallPath();
return new(new(installPath, DnupUtilities.GetDefaultInstallArchitecture()), installtype, true, true);
return new(new(installPath, InstallerUtilities.GetDefaultInstallArchitecture()), installtype, true, true);
}

public string? GetLatestInstalledAdminVersion()
Expand Down
7 changes: 4 additions & 3 deletions src/Installer/dnup/Commands/Sdk/Install/SdkInstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using SpectreAnsiConsole = Spectre.Console.AnsiConsole;
using Microsoft.DotNet.Tools.Bootstrapper.Commands.Sdk.Install;
using System.Runtime.InteropServices;
using Microsoft.Dotnet.Installation.Internal;

namespace Microsoft.DotNet.Tools.Bootstrapper.Commands.Sdk.Install;

Expand All @@ -23,7 +24,7 @@ internal class SdkInstallCommand(ParseResult result) : CommandBase(result)
private readonly bool _interactive = result.GetValue(SdkInstallCommandParser.InteractiveOption);
private readonly bool _noProgress = result.GetValue(SdkInstallCommandParser.NoProgressOption);

private readonly IBootstrapperController _dotnetInstaller = new BootstrapperController();
private readonly IDotnetInstallManager _dotnetInstaller = new DotnetInstallManager();
private readonly IDotnetReleaseInfoProvider _releaseInfoProvider = new EnvironmentVariableMockReleaseInfoProvider();
private readonly ManifestChannelVersionResolver _channelVersionResolver = new ManifestChannelVersionResolver();

Expand Down Expand Up @@ -175,7 +176,7 @@ public override int Execute()

// Create a request and resolve it using the channel version resolver
var installRequest = new DotnetInstallRequest(
new DotnetInstallRoot(resolvedInstallPath, DnupUtilities.GetInstallArchitecture(RuntimeInformation.ProcessArchitecture)),
new DotnetInstallRoot(resolvedInstallPath, InstallerUtilities.GetDefaultInstallArchitecture()),
new UpdateChannel(resolvedChannel),
InstallComponent.SDK,
new InstallRequestOptions
Expand Down Expand Up @@ -229,7 +230,7 @@ public override int Execute()
{
// Create the request for the additional version
var additionalRequest = new DotnetInstallRequest(
new DotnetInstallRoot(resolvedInstallPath, DnupUtilities.GetInstallArchitecture(RuntimeInformation.ProcessArchitecture)),
new DotnetInstallRoot(resolvedInstallPath, InstallerUtilities.GetDefaultInstallArchitecture()),
new UpdateChannel(additionalVersion),
InstallComponent.SDK,
new InstallRequestOptions
Expand Down
7 changes: 3 additions & 4 deletions src/Installer/dnup/DnupManifestJsonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@

using System.Text.Json.Serialization;
using System.Collections.Generic;
using Microsoft.Dotnet.Installation.Internal;

namespace Microsoft.DotNet.Tools.Bootstrapper
{
[JsonSourceGenerationOptions(WriteIndented = false, PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
Converters = new[] { typeof(DotnetVersionJsonConverter), typeof(ReleaseVersionJsonConverter) })]
Converters = new[] { typeof(ReleaseVersionJsonConverter) })]
[JsonSerializable(typeof(List<DotnetInstall>))]
[JsonSerializable(typeof(DotnetVersion))]
[JsonSerializable(typeof(DotnetVersionType))]
[JsonSerializable(typeof(InstallComponent))]
[JsonSerializable(typeof(InstallArchitecture))]
[JsonSerializable(typeof(InstallType))]
[JsonSerializable(typeof(ManagementCadence))]
public partial class DnupManifestJsonContext : JsonSerializerContext { }
internal partial class DnupManifestJsonContext : JsonSerializerContext { }
}
1 change: 1 addition & 0 deletions src/Installer/dnup/DnupSharedManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Text.Json;
using System.Threading;
using Microsoft.Dotnet.Installation.Internal;

namespace Microsoft.DotNet.Tools.Bootstrapper;

Expand Down
Loading