Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
<Folder Name="/src/Cli/">
<Project Path="src/Cli/dotnet/dotnet.csproj" />
<Project Path="src/Cli/Microsoft.DotNet.Cli.CommandLine/Microsoft.DotNet.Cli.CommandLine.csproj" />
<Project Path="src/Cli/Microsoft.DotNet.Cli.CoreUtils/Microsoft.DotNet.Cli.CoreUtils.csproj" />
<Project Path="src/Cli/Microsoft.DotNet.Cli.Definitions/Microsoft.DotNet.Cli.Definitions.csproj" />
<Project Path="src/Cli/Microsoft.DotNet.Cli.Utils/Microsoft.DotNet.Cli.Utils.csproj" />
<Project Path="src/Cli/Microsoft.DotNet.Configurer/Microsoft.DotNet.Configurer.csproj" />
<Project Path="src/Cli/Microsoft.DotNet.FileBasedPrograms/Microsoft.DotNet.FileBasedPrograms.Package.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET

using System.Reflection;

namespace Microsoft.DotNet.Cli.Utils;

internal static class DotnetFiles
public static class DotnetFiles
{
private static string SdkRootFolder => Path.Combine(typeof(DotnetFiles).GetTypeInfo().Assembly.Location, "..");

Expand All @@ -17,5 +19,7 @@ internal static class DotnetFiles
/// </summary>
public static string VersionFile => Path.GetFullPath(Path.Combine(SdkRootFolder, ".version"));

internal static DotnetVersionFile VersionFileObject => s_versionFileObject.Value;
public static DotnetVersionFile VersionFileObject => s_versionFileObject.Value;
}

#endif
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET

namespace Microsoft.DotNet.Cli.Utils;

internal class DotnetVersionFile
public class DotnetVersionFile
{
public bool Exists { get; init; }

Expand Down Expand Up @@ -67,3 +69,5 @@ public DotnetVersionFile(string versionFilePath)
}
}
}

#endif
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.

namespace Microsoft.DotNet.Cli;

public static class EnvironmentVariableParser
{
public static bool ParseBool(string? str, bool defaultValue)
{
if (str is "1" ||
string.Equals(str, "true", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "yes", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "on", StringComparison.OrdinalIgnoreCase))
{
return true;
}

if (str is "0" ||
string.Equals(str, "false", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "no", StringComparison.OrdinalIgnoreCase) ||
string.Equals(str, "off", StringComparison.OrdinalIgnoreCase))
{
return false;
}

return defaultValue;
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.DotNet.Cli.Utils.Extensions;
namespace Microsoft.DotNet.Cli.Utils;

internal static class ExceptionExtensions
public static class ExceptionExtensions
{
public static TException DisplayAsError<TException>(this TException exception)
where TException : Exception
where TException : Exception
{
exception.Data.Add(CLI_User_Displayed_Exception, true);
return exception;
}

public static void ReportAsWarning(this Exception e)
{
Reporter.Verbose.WriteLine($"Warning: Ignoring exception: {e.ToString().Yellow()}");
}

public static bool ShouldBeDisplayedAsError(this Exception e) =>
e.Data.Contains(CLI_User_Displayed_Exception);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.Cli.Utils.Extensions;

namespace Microsoft.DotNet.Cli.Utils;

public class GracefulException : Exception
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(SdkTargetFramework);net472</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<Nullable>enable</Nullable>
<StrongNameKeyId>MicrosoftAspNetCore</StrongNameKeyId>
</PropertyGroup>
</Project>
24 changes: 24 additions & 0 deletions src/Cli/Microsoft.DotNet.Cli.CoreUtils/PathUtilities.cs
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.

namespace Microsoft.DotNet.Cli;

public static class PathUtilities
{
public static string EnsureTrailingSlash(string path)
=> EnsureTrailingCharacter(path, Path.DirectorySeparatorChar);

public static string EnsureTrailingForwardSlash(string path)
=> EnsureTrailingCharacter(path, '/');

private static string EnsureTrailingCharacter(string path, char trailingCharacter)
{
// if the path is empty, we want to return the original string instead of a single trailing character.
if (path.Length == 0 || path[path.Length - 1] == trailingCharacter)
{
return path;
}

return path + trailingCharacter;
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#if NET

using System.Reflection;

namespace Microsoft.DotNet.Cli.Utils;

public static class Product
{
public static string LongName => LocalizableStrings.DotNetSdkInfo;
public static readonly string Version;
public static readonly string TargetFrameworkVersion;

Expand All @@ -34,3 +35,5 @@ static Product()
}
}
}

#endif
Loading