Skip to content

Commit 8cfe2ea

Browse files
committed
Cleanup
1 parent 02aa3f9 commit 8cfe2ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+740
-492
lines changed

src/Cli/dotnet/Commands/CliCommandStrings.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,9 @@ Make the profile names distinct.</value>
10421042
<data name="LaunchProfileIsNotAJsonObject" xml:space="preserve">
10431043
<value>A profile with the specified name isn't a valid JSON object.</value>
10441044
</data>
1045+
<data name="LaunchProfile0IsMissingProperty1" xml:space="preserve">
1046+
<value>Launch profile '{0}' is missing property '{1}'</value>
1047+
</data>
10451048
<data name="LaunchProfilesCollectionIsNotAJsonObject" xml:space="preserve">
10461049
<value>The 'profiles' property of the launch settings document is not a JSON object.</value>
10471050
</data>
@@ -1746,6 +1749,9 @@ Your project targets multiple frameworks. Specify which framework to run using '
17461749
<data name="RunCommandSpecifiedFileIsNotAValidProject" xml:space="preserve">
17471750
<value>'{0}' is not a valid project file.</value>
17481751
</data>
1752+
<data name="Path0SpecifiedIn1IsInvalid" xml:space="preserve">
1753+
<value>Path '{0}' specified in '{1}' is invalid.</value>
1754+
</data>
17491755
<data name="RunConfigurationOptionDescription" xml:space="preserve">
17501756
<value>The configuration to run for. The default for most projects is 'Debug'.</value>
17511757
</data>

src/Cli/dotnet/Commands/Run/Api/RunApiCommand.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ public override RunApiOutput Execute()
111111
environmentVariables: ReadOnlyDictionary<string, string>.Empty,
112112
msbuildRestoreProperties: ReadOnlyDictionary<string, string>.Empty);
113113

114-
runCommand.TryGetLaunchProfileSettingsIfNeeded(out var launchSettings);
115-
var targetCommand = (Utils.Command)runCommand.GetTargetCommand(buildCommand.CreateProjectInstance, cachedRunProperties: null);
116-
runCommand.ApplyLaunchSettingsProfileToCommand(targetCommand, launchSettings);
114+
var result = runCommand.ReadLaunchProfileSettings();
115+
var targetCommand = (Utils.Command)runCommand.GetTargetCommand(result.Model, buildCommand.CreateProjectInstance, cachedRunProperties: null);
117116

118117
return new RunApiOutput.RunCommand
119118
{

src/Cli/dotnet/Commands/Run/LaunchSettings/ExecutableLaunchProfileJson.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ internal class ExecutableLaunchProfileJson
1919
[JsonPropertyName("workingDirectory")]
2020
public string? WorkingDirectory { get; set; }
2121

22+
[JsonPropertyName("dotnetRunMessages")]
23+
public string? DotNetRunMessages { get; set; }
24+
2225
[JsonPropertyName("environmentVariables")]
2326
public Dictionary<string, string>? EnvironmentVariables { get; set; }
2427
}

src/Cli/dotnet/Commands/Run/LaunchSettings/ExecutableLaunchSettingsModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
namespace Microsoft.DotNet.Cli.Commands.Run.LaunchSettings;
55

6-
public class ExecutableLaunchSettingsModel : LaunchSettingsModel
6+
public sealed class ExecutableLaunchSettingsModel : LaunchSettingsModel
77
{
8-
public string? ExecutablePath { get; set; }
8+
public const string WorkingDirectoryPropertyName = "workingDirectory";
9+
public const string ExecutablePathPropertyName = "executablePath";
910

10-
public string? WorkingDirectory { get; set; }
11-
12-
public override LaunchProfileKind ProfileKind => LaunchProfileKind.Executable;
11+
public required string ExecutablePath { get; init; }
12+
public string? WorkingDirectory { get; init; }
1313
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Immutable;
5+
using System.Text.Json;
6+
7+
namespace Microsoft.DotNet.Cli.Commands.Run.LaunchSettings;
8+
9+
internal sealed class ExecutableLaunchSettingsParser : LaunchProfileParser
10+
{
11+
public const string CommandName = "Executable";
12+
13+
public override LaunchProfileSettings ParseProfile(string launchSettingsPath, string? launchProfileName, string json)
14+
{
15+
var profile = JsonSerializer.Deserialize<ExecutableLaunchProfileJson>(json);
16+
if (profile == null)
17+
{
18+
return LaunchProfileSettings.Failure(CliCommandStrings.LaunchProfileIsNotAJsonObject);
19+
}
20+
21+
if (profile.ExecutablePath == null)
22+
{
23+
return LaunchProfileSettings.Failure(
24+
string.Format(
25+
CliCommandStrings.LaunchProfile0IsMissingProperty1,
26+
RunCommand.GetLaunchProfileDisplayName(launchProfileName),
27+
ExecutableLaunchSettingsModel.ExecutablePathPropertyName));
28+
}
29+
30+
return LaunchProfileSettings.Success(new ExecutableLaunchSettingsModel
31+
{
32+
LaunchSettingsPath = launchSettingsPath,
33+
LaunchProfileName = launchProfileName,
34+
ExecutablePath = profile.ExecutablePath,
35+
CommandLineArgs = profile.CommandLineArgs,
36+
WorkingDirectory = profile.WorkingDirectory,
37+
DotNetRunMessages = ParseDotNetRunMessages(profile.DotNetRunMessages),
38+
EnvironmentVariables = ParseEnvironmentVariables(profile.EnvironmentVariables),
39+
});
40+
}
41+
}

src/Cli/dotnet/Commands/Run/LaunchSettings/ExecutableLaunchSettingsProvider.cs

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/Cli/dotnet/Commands/Run/LaunchSettings/ILaunchSettingsProvider.cs

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Immutable;
5+
6+
namespace Microsoft.DotNet.Cli.Commands.Run.LaunchSettings;
7+
8+
internal abstract class LaunchProfileParser
9+
{
10+
public abstract LaunchProfileSettings ParseProfile(string launchSettingsPath, string? launchProfileName, string json);
11+
12+
protected static bool ParseDotNetRunMessages(string? value)
13+
=> string.Equals(value, "true", StringComparison.OrdinalIgnoreCase);
14+
15+
protected static ImmutableDictionary<string, string> ParseEnvironmentVariables(Dictionary<string, string>? values)
16+
{
17+
if (values is null or { Count: 0 })
18+
{
19+
return [];
20+
}
21+
22+
var builder = ImmutableDictionary.CreateBuilder<string, string>(StringComparer.Ordinal);
23+
foreach (var (key, value) in values)
24+
{
25+
// override previously set variables:
26+
builder[key] = value;
27+
}
28+
29+
return builder.ToImmutable();
30+
}
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Diagnostics.CodeAnalysis;
5+
6+
namespace Microsoft.DotNet.Cli.Commands.Run.LaunchSettings;
7+
8+
public sealed class LaunchProfileSettings
9+
{
10+
public string? FailureReason { get; }
11+
12+
public LaunchSettingsModel? Model { get; }
13+
14+
private LaunchProfileSettings(string? failureReason, LaunchSettingsModel? launchSettings)
15+
{
16+
FailureReason = failureReason;
17+
Model = launchSettings;
18+
}
19+
20+
[MemberNotNullWhen(false, nameof(FailureReason))]
21+
public bool Successful
22+
=> FailureReason == null;
23+
24+
public static LaunchProfileSettings Failure(string reason)
25+
=> new(reason, launchSettings: null);
26+
27+
public static LaunchProfileSettings Success(LaunchSettingsModel? model)
28+
=> new(failureReason: null, launchSettings: model);
29+
}

src/Cli/dotnet/Commands/Run/LaunchSettings/LaunchSettingsApplyResult.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)