Skip to content
Open
Prev Previous commit
Next Next commit
Renames
  • Loading branch information
tmat committed Dec 11, 2025
commit 5f4094fa3934f95a14785e6771a62951bd428d5c
2 changes: 1 addition & 1 deletion src/BuiltInTools/Watch/Process/LaunchSettingsProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal sealed class LaunchSettingsProfile

internal static LaunchSettingsProfile? ReadLaunchProfile(string projectPath, string? launchProfileName, ILogger logger)
{
var launchSettingsPath = LaunchSettingsLocator.TryFindLaunchSettings(projectPath, launchProfileName, (message, isError) =>
var launchSettingsPath = LaunchSettings.TryFindLaunchSettingsFile(projectPath, launchProfileName, (message, isError) =>
{
if (isError)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Run/Api/RunApiCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public override RunApiOutput Execute()
msbuildRestoreProperties: ReadOnlyDictionary<string, string>.Empty);

var result = runCommand.ReadLaunchProfileSettings();
var targetCommand = (Utils.Command)runCommand.GetTargetCommand(result.Model, buildCommand.CreateProjectInstance, cachedRunProperties: null);
var targetCommand = (Utils.Command)runCommand.GetTargetCommand(result.Profile, buildCommand.CreateProjectInstance, cachedRunProperties: null);

return new RunApiOutput.RunCommand
{
Expand Down
44 changes: 22 additions & 22 deletions src/Cli/dotnet/Commands/Run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,25 @@ public int Execute()
return 1;
}

var launchProfileSettings = ReadLaunchProfileSettings();
if (launchProfileSettings.FailureReason != null)
var launchProfileParseResult = ReadLaunchProfileSettings();
if (launchProfileParseResult.FailureReason != null)
{
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotApplyLaunchSettings, LaunchProfileParser.GetLaunchProfileDisplayName(LaunchProfile), launchProfileSettings.FailureReason).Bold().Red());
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotApplyLaunchSettings, LaunchProfileParser.GetLaunchProfileDisplayName(LaunchProfile), launchProfileParseResult.FailureReason).Bold().Red());
}

Func<ProjectCollection, ProjectInstance>? projectFactory = null;
RunProperties? cachedRunProperties = null;
VirtualProjectBuildingCommand? projectBuilder = null;
if (ShouldBuild)
{
if (launchProfileSettings.Model?.DotNetRunMessages == true)
if (launchProfileParseResult.Profile?.DotNetRunMessages == true)
{
Reporter.Output.WriteLine(CliCommandStrings.RunCommandBuilding);
}

EnsureProjectIsBuilt(out projectFactory, out cachedRunProperties, out projectBuilder);
}
else if (EntryPointFileFullPath is not null && launchProfileSettings.Model is not ExecutableLaunchSettings)
else if (EntryPointFileFullPath is not null && launchProfileParseResult.Profile is not ExecutableLaunchProfile)
{
// The entry-point is not used to run the application if the launch profile specifies Executable command.

Expand All @@ -173,23 +173,23 @@ public int Execute()
cachedRunProperties = cacheEntry?.Run;
}

var targetCommand = GetTargetCommand(launchProfileSettings.Model, projectFactory, cachedRunProperties);
var targetCommand = GetTargetCommand(launchProfileParseResult.Profile, projectFactory, cachedRunProperties);

// Send telemetry about the run operation
SendRunTelemetry(launchProfileSettings.Model, projectBuilder);
SendRunTelemetry(launchProfileParseResult.Profile, projectBuilder);

// Ignore Ctrl-C for the remainder of the command's execution
Console.CancelKeyPress += (sender, e) => { e.Cancel = true; };

return targetCommand.Execute().ExitCode;
}

internal ICommand GetTargetCommand(LaunchSettings? launchSettings, Func<ProjectCollection, ProjectInstance>? projectFactory, RunProperties? cachedRunProperties)
internal ICommand GetTargetCommand(LaunchProfile? launchSettings, Func<ProjectCollection, ProjectInstance>? projectFactory, RunProperties? cachedRunProperties)
=> launchSettings switch
{
null => GetTargetCommandForProject(launchSettings: null, projectFactory, cachedRunProperties),
ProjectLaunchSettings projectSettings => GetTargetCommandForProject(projectSettings, projectFactory, cachedRunProperties),
ExecutableLaunchSettings executableSettings => GetTargetCommandForExecutable(executableSettings),
ProjectLaunchProfile projectSettings => GetTargetCommandForProject(projectSettings, projectFactory, cachedRunProperties),
ExecutableLaunchProfile executableSettings => GetTargetCommandForExecutable(executableSettings),
_ => throw new InvalidOperationException()
};

Expand Down Expand Up @@ -287,7 +287,7 @@ private void ApplySelectedFramework(string? selectedFramework)
}
}

private ICommand GetTargetCommandForExecutable(ExecutableLaunchSettings launchSettings)
private ICommand GetTargetCommandForExecutable(ExecutableLaunchProfile launchSettings)
{
var workingDirectory = launchSettings.WorkingDirectory ?? Path.GetDirectoryName(ProjectOrEntryPointPath);

Expand All @@ -304,10 +304,10 @@ private ICommand GetTargetCommandForExecutable(ExecutableLaunchSettings launchSe
return command;
}

private void SetEnvironmentVariables(ICommand command, LaunchSettings? launchSettings)
private void SetEnvironmentVariables(ICommand command, LaunchProfile? launchSettings)
{
// Handle Project-specific settings
if (launchSettings is ProjectLaunchSettings projectSettings)
if (launchSettings is ProjectLaunchProfile projectSettings)
{
if (!string.IsNullOrEmpty(projectSettings.ApplicationUrl))
{
Expand All @@ -332,31 +332,31 @@ private void SetEnvironmentVariables(ICommand command, LaunchSettings? launchSet
}
}

internal LaunchProfileSettings ReadLaunchProfileSettings()
internal LaunchProfileParseResult ReadLaunchProfileSettings()
{
if (NoLaunchProfile)
{
return LaunchProfileSettings.Success(model: null);
return LaunchProfileParseResult.Success(model: null);
}

var launchSettingsPath = ReadCodeFromStdin
? null
: LaunchSettingsLocator.TryFindLaunchSettings(
: LaunchSettings.TryFindLaunchSettingsFile(
projectOrEntryPointFilePath: ProjectFileFullPath ?? EntryPointFileFullPath!,
launchProfile: LaunchProfile,
static (message, isError) => (isError ? Reporter.Error : Reporter.Output).WriteLine(message));

if (launchSettingsPath is null)
{
return LaunchProfileSettings.Success(model: null);
return LaunchProfileParseResult.Success(model: null);
}

if (!RunCommandVerbosity.IsQuiet())
{
Reporter.Output.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}

return LaunchSettingsManager.ReadProfileSettingsFromFile(launchSettingsPath, LaunchProfile);
return LaunchSettings.ReadProfileSettingsFromFile(launchSettingsPath, LaunchProfile);
}

private void EnsureProjectIsBuilt(out Func<ProjectCollection, ProjectInstance>? projectFactory, out RunProperties? cachedRunProperties, out VirtualProjectBuildingCommand? projectBuilder)
Expand Down Expand Up @@ -438,7 +438,7 @@ private MSBuildArgs SetupSilentBuildArgs(MSBuildArgs msbuildArgs)
}
}

private ICommand GetTargetCommandForProject(ProjectLaunchSettings? launchSettings, Func<ProjectCollection, ProjectInstance>? projectFactory, RunProperties? cachedRunProperties)
private ICommand GetTargetCommandForProject(ProjectLaunchProfile? launchSettings, Func<ProjectCollection, ProjectInstance>? projectFactory, RunProperties? cachedRunProperties)
{
ICommand command;
if (cachedRunProperties != null)
Expand Down Expand Up @@ -844,7 +844,7 @@ public static ParseResult ModifyParseResultForShorthandProjectOption(ParseResult
/// Sends telemetry about the run operation.
/// </summary>
private void SendRunTelemetry(
LaunchSettings? launchSettings,
LaunchProfile? launchSettings,
VirtualProjectBuildingCommand? projectBuilder)
{
try
Expand Down Expand Up @@ -872,7 +872,7 @@ private void SendRunTelemetry(
/// Builds and sends telemetry data for file-based app runs.
/// </summary>
private void SendFileBasedTelemetry(
LaunchSettings? launchSettings,
LaunchProfile? launchSettings,
VirtualProjectBuildingCommand projectBuilder)
{
Debug.Assert(EntryPointFileFullPath != null);
Expand Down Expand Up @@ -901,7 +901,7 @@ private void SendFileBasedTelemetry(
/// <summary>
/// Builds and sends telemetry data for project-based app runs.
/// </summary>
private void SendProjectBasedTelemetry(LaunchSettings? launchSettings)
private void SendProjectBasedTelemetry(LaunchProfile? launchSettings)
{
Debug.Assert(ProjectFileFullPath != null);
var projectIdentifier = RunTelemetry.GetProjectBasedIdentifier(ProjectFileFullPath, GetRepositoryRoot(), Sha256Hasher.Hash);
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Run/RunTelemetry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void TrackRunEvent(
string projectIdentifier,
string? launchProfile = null,
bool noLaunchProfile = false,
LaunchSettings? launchSettings = null,
LaunchProfile? launchSettings = null,
int sdkCount = 1,
int packageReferenceCount = 0,
int projectReferenceCount = 0,
Expand Down
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Test/MTP/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ public bool MoveNext()
}
}

internal sealed record TestModule(RunProperties RunProperties, string? ProjectFullPath, string? TargetFramework, bool IsTestingPlatformApplication, LaunchSettings? LaunchSettings, string TargetPath, string? DotnetRootArchVariableName);
internal sealed record TestModule(RunProperties RunProperties, string? ProjectFullPath, string? TargetFramework, bool IsTestingPlatformApplication, LaunchProfile? LaunchSettings, string TargetPath, string? DotnetRootArchVariableName);
10 changes: 5 additions & 5 deletions src/Cli/dotnet/Commands/Test/MTP/SolutionAndProjectUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,17 @@ static RunProperties GetRunProperties(ProjectInstance project)
}
}

private static LaunchSettings? TryGetLaunchProfileSettings(string projectDirectory, string projectNameWithoutExtension, string appDesignerFolder, BuildOptions buildOptions, string? profileName)
private static LaunchProfile? TryGetLaunchProfileSettings(string projectDirectory, string projectNameWithoutExtension, string appDesignerFolder, BuildOptions buildOptions, string? profileName)
{
if (buildOptions.NoLaunchProfile)
{
return null;
}

var launchSettingsPath = LaunchSettingsLocator.GetPropertiesLaunchSettingsPath(projectDirectory, appDesignerFolder);
var launchSettingsPath = LaunchSettings.GetPropertiesLaunchSettingsPath(projectDirectory, appDesignerFolder);
bool hasLaunchSettings = File.Exists(launchSettingsPath);

var runJsonPath = LaunchSettingsLocator.GetFlatLaunchSettingsPath(projectDirectory, projectNameWithoutExtension);
var runJsonPath = LaunchSettings.GetFlatLaunchSettingsPath(projectDirectory, projectNameWithoutExtension);
bool hasRunJson = File.Exists(runJsonPath);

if (hasLaunchSettings)
Expand All @@ -406,13 +406,13 @@ static RunProperties GetRunProperties(ProjectInstance project)
Reporter.Output.WriteLine(string.Format(CliCommandStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}

var result = LaunchSettingsManager.ReadProfileSettingsFromFile(launchSettingsPath, profileName);
var result = LaunchSettings.ReadProfileSettingsFromFile(launchSettingsPath, profileName);
if (!result.Successful)
{
Reporter.Error.WriteLine(string.Format(CliCommandStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, result.FailureReason).Bold().Red());
return null;
}

return result.Model;
return result.Profile;
}
}
2 changes: 1 addition & 1 deletion src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private ProcessStartInfo CreateProcessStartInfo()
processStartInfo.WorkingDirectory = Module.RunProperties.WorkingDirectory;
}

if (Module.LaunchSettings is ProjectLaunchSettings)
if (Module.LaunchSettings is ProjectLaunchProfile)
{
foreach (var entry in Module.LaunchSettings.EnvironmentVariables)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.DotNet.ProjectTools;

public sealed class ExecutableLaunchSettings : LaunchSettings
public sealed class ExecutableLaunchProfile : LaunchProfile
{
public const string WorkingDirectoryPropertyName = "workingDirectory";
public const string ExecutablePathPropertyName = "executablePath";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Microsoft.DotNet.ProjectTools;

internal sealed class ExecutableLaunchSettingsParser : LaunchProfileParser
internal sealed class ExecutableLaunchProfileParser : LaunchProfileParser
{
private sealed class Json
{
Expand All @@ -32,35 +32,35 @@ private sealed class Json

public const string CommandName = "Executable";

public static readonly ExecutableLaunchSettingsParser Instance = new();
public static readonly ExecutableLaunchProfileParser Instance = new();

private ExecutableLaunchSettingsParser()
private ExecutableLaunchProfileParser()
{
}

public override LaunchProfileSettings ParseProfile(string launchSettingsPath, string? launchProfileName, string json)
public override LaunchProfileParseResult ParseProfile(string launchSettingsPath, string? launchProfileName, string json)
{
var profile = JsonSerializer.Deserialize<Json>(json);
if (profile == null)
{
return LaunchProfileSettings.Failure(Resources.LaunchProfileIsNotAJsonObject);
return LaunchProfileParseResult.Failure(Resources.LaunchProfileIsNotAJsonObject);
}

if (profile.ExecutablePath == null)
{
return LaunchProfileSettings.Failure(
return LaunchProfileParseResult.Failure(
string.Format(
Resources.LaunchProfile0IsMissingProperty1,
LaunchProfileParser.GetLaunchProfileDisplayName(launchProfileName),
ExecutableLaunchSettings.ExecutablePathPropertyName));
ExecutableLaunchProfile.ExecutablePathPropertyName));
}

if (!TryParseWorkingDirectory(launchSettingsPath, profile.WorkingDirectory, out var workingDirectory, out var error))
{
return LaunchProfileSettings.Failure(error);
return LaunchProfileParseResult.Failure(error);
}

return LaunchProfileSettings.Success(new ExecutableLaunchSettings
return LaunchProfileParseResult.Success(new ExecutableLaunchProfile
{
LaunchProfileName = launchProfileName,
ExecutablePath = ExpandVariables(profile.ExecutablePath),
Expand Down Expand Up @@ -91,7 +91,7 @@ private static bool TryParseWorkingDirectory(string launchSettingsPath, string?
catch
{
workingDirectory = null;
error = string.Format(Resources.Path0SpecifiedIn1IsInvalid, expandedValue, ExecutableLaunchSettings.WorkingDirectoryPropertyName);
error = string.Format(Resources.Path0SpecifiedIn1IsInvalid, expandedValue, ExecutableLaunchProfile.WorkingDirectoryPropertyName);
return false;
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/Microsoft.DotNet.ProjectTools/LaunchSettings/LaunchProfile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;

namespace Microsoft.DotNet.ProjectTools;

public abstract class LaunchProfile
{
public string? LaunchProfileName { get; init; }

public bool DotNetRunMessages { get; init; }

public string? CommandLineArgs { get; init; }

public required ImmutableDictionary<string, string> EnvironmentVariables { get; init; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.DotNet.ProjectTools;

public sealed class LaunchProfileParseResult
{
public string? FailureReason { get; }

public LaunchProfile? Profile { get; }

private LaunchProfileParseResult(string? failureReason, LaunchProfile? profile)
{
FailureReason = failureReason;
Profile = profile;
}

[MemberNotNullWhen(false, nameof(FailureReason))]
public bool Successful
=> FailureReason == null;

public static LaunchProfileParseResult Failure(string reason)
=> new(reason, profile: null);

public static LaunchProfileParseResult Success(LaunchProfile? model)
=> new(failureReason: null, profile: model);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.ProjectTools;

internal abstract class LaunchProfileParser
{
public abstract LaunchProfileSettings ParseProfile(string launchSettingsPath, string? launchProfileName, string json);
public abstract LaunchProfileParseResult ParseProfile(string launchSettingsPath, string? launchProfileName, string json);

protected static string? ParseCommandLineArgs(string? value)
=> value != null ? ExpandVariables(value) : null;
Expand Down

This file was deleted.

Loading