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: 1 addition & 1 deletion eng/restore-toolset.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function InitializeCustomSDKToolset {
if ($env:TestFullMSBuild -eq "true") {
$env:DOTNET_SDK_TEST_MSBUILD_PATH = InitializeVisualStudioMSBuild -install:$true -vsRequirements:$GlobalJson.tools.'vs-opt'
$env:DOTNET_SDK_TEST_MSBUILD_PATH = InitializeVisualStudioMSBuild -install:$false -vsRequirements:$GlobalJson.tools.'vs-opt'
Write-Host "INFO: Tests will run against full MSBuild in $env:DOTNET_SDK_TEST_MSBUILD_PATH"
}

Expand Down
5 changes: 2 additions & 3 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
]
},
"vs-opt": {
"version": "16.8"
},
"xcopy-msbuild": "16.8.0-preview1"
"version": "15.9"
}
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "5.0.0-beta.20364.3",
Expand Down
16 changes: 0 additions & 16 deletions src/Assets/TestProjects/TestAppWithLaunchSettings/Program.cs

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings
{
internal interface ILaunchSettingsProvider
{
LaunchSettingsApplyResult TryGetLaunchSettings(JsonElement model);
string CommandName { get; }

LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref ICommand command);
}

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
// 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.

namespace Microsoft.DotNet.Tools.Run.LaunchSettings
{
public class LaunchSettingsApplyResult
{
public LaunchSettingsApplyResult(bool success, string failureReason, ProjectLaunchSettingsModel launchSettings = null)
public LaunchSettingsApplyResult(bool success, string failureReason, string runAfterLaunch = null)
{
Success = success;
FailureReason = failureReason;
LaunchSettings = launchSettings;
RunAfterLaunch = runAfterLaunch;
}

public bool Success { get; }

public string FailureReason { get; }

public ProjectLaunchSettingsModel LaunchSettings { get; }
public string RunAfterLaunch { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// 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;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
Expand All @@ -24,7 +21,7 @@ static LaunchSettingsManager()
};
}

public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSettingsJsonContents, string profileName = null)
public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSettingsJsonContents, ref ICommand command, string profileName = null)
{
try
{
Expand Down Expand Up @@ -93,7 +90,7 @@ public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSett
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.LaunchProfileHandlerCannotBeLocated, commandName));
}

return provider.TryGetLaunchSettings(profileObject);
return provider.TryApplySettings(profileObject, ref command);
}
}
catch (JsonException ex)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// 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;
using System;
using System.Collections.Generic;
using System.Text.Json;
using Microsoft.DotNet.Cli.Utils;

namespace Microsoft.DotNet.Tools.Run.LaunchSettings
{
Expand All @@ -12,7 +11,7 @@ internal class ProjectLaunchSettingsProvider : ILaunchSettingsProvider

public string CommandName => CommandNameValue;

public LaunchSettingsApplyResult TryGetLaunchSettings(JsonElement model)
public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref ICommand command)
{
var config = new ProjectLaunchSettingsModel();
foreach (var property in model.EnumerateObject())
Expand Down Expand Up @@ -53,23 +52,14 @@ public LaunchSettingsApplyResult TryGetLaunchSettings(JsonElement model)

config.ApplicationUrl = applicationUrlValue;
}
else if (string.Equals(property.Name, nameof(ProjectLaunchSettingsModel.DotNetRunMessages), StringComparison.OrdinalIgnoreCase))
{
if (!TryGetStringValue(property.Value, out var dotNetRunMessages))
{
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.CouldNotConvertToString, property.Name));
}

config.DotNetRunMessages = dotNetRunMessages;
}
else if (string.Equals(property.Name, nameof(ProjectLaunchSettingsModel.EnvironmentVariables), StringComparison.OrdinalIgnoreCase))
{
if (property.Value.ValueKind != JsonValueKind.Object)
{
return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.ValueMustBeAnObject, property.Name));
}

foreach (var environmentVariable in property.Value.EnumerateObject())
foreach(var environmentVariable in property.Value.EnumerateObject())
{
if (TryGetStringValue(environmentVariable.Value, out var environmentVariableValue))
{
Expand All @@ -79,7 +69,21 @@ public LaunchSettingsApplyResult TryGetLaunchSettings(JsonElement model)
}
}

return new LaunchSettingsApplyResult(true, null, config);
if (!string.IsNullOrEmpty(config.ApplicationUrl))
{
command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl);
}

//For now, ignore everything but the environment variables section

foreach (var entry in config.EnvironmentVariables)
{
string value = Environment.ExpandEnvironmentVariables(entry.Value);
//NOTE: MSBuild variables are not expanded like they are in VS
command.EnvironmentVariable(entry.Key, value);
}

return new LaunchSettingsApplyResult(true, null, config.LaunchUrl);
}

private static bool TryGetBooleanValue(JsonElement element, out bool value)
Expand Down Expand Up @@ -132,5 +136,23 @@ private static bool TryGetStringValue(JsonElement element, out string value)
return false;
}
}

private class ProjectLaunchSettingsModel
{
public ProjectLaunchSettingsModel()
{
EnvironmentVariables = new Dictionary<string, string>(StringComparer.Ordinal);
}

public string CommandLineArgs { get; set; }

public bool LaunchBrowser { get; set; }

public string LaunchUrl { get; set; }

public string ApplicationUrl { get; set; }

public Dictionary<string, string> EnvironmentVariables { get; }
}
}
}
5 changes: 1 addition & 4 deletions src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,6 @@
<data name="RuntimeOptionDescription" xml:space="preserve">
<value>The target runtime to run for.</value>
</data>
<data name="RunCommandBuilding" xml:space="preserve">
<value>Building...</value>
</data>
<data name="RunCommandException" xml:space="preserve">
<value>The build failed. Fix the build errors and run again.</value>
</data>
Expand Down Expand Up @@ -217,4 +214,4 @@ The current {1} is '{2}'.</value>
<data name="ValueMustBeAnObject" xml:space="preserve">
<value>The property '{0}' must be an object if it is specified.</value>
</data>
</root>
</root>
40 changes: 8 additions & 32 deletions src/Cli/dotnet/commands/dotnet-run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using Microsoft.Build.Execution;
using Microsoft.Build.Exceptions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
using Microsoft.DotNet.Tools.MSBuild;
using Microsoft.DotNet.Tools.Run.LaunchSettings;
using Microsoft.DotNet.CommandFactory;

Expand Down Expand Up @@ -39,37 +41,17 @@ public int Execute()
{
Initialize();

if (!TryGetLaunchProfileSettingsIfNeeded(out var launchSettings))
{
return 1;
}

if (ShouldBuild)
{
if (string.Equals("true", launchSettings?.DotNetRunMessages, StringComparison.OrdinalIgnoreCase))
{
Reporter.Output.WriteLine(LocalizableStrings.RunCommandBuilding);
}

EnsureProjectIsBuilt();
}

try
{
ICommand targetCommand = GetTargetCommand();
if (launchSettings != null)
if (!ApplyLaunchProfileSettingsIfNeeded(ref targetCommand))
{
if (!string.IsNullOrEmpty(launchSettings.ApplicationUrl))
{
targetCommand.EnvironmentVariable("ASPNETCORE_URLS", launchSettings.ApplicationUrl);
}

foreach (var entry in launchSettings.EnvironmentVariables)
{
string value = Environment.ExpandEnvironmentVariables(entry.Value);
//NOTE: MSBuild variables are not expanded like they are in VS
targetCommand.EnvironmentVariable(entry.Key, value);
}
return 1;
}

// Ignore Ctrl-C for the remainder of the command's execution
Expand Down Expand Up @@ -110,9 +92,8 @@ public RunCommand(string configuration,
Interactive = interactive;
}

private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel launchSettingsModel)
private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand)
{
launchSettingsModel = default;
if (!UseLaunchProfile)
{
return true;
Expand All @@ -136,8 +117,7 @@ private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel

if (File.Exists(launchSettingsPath))
{
if (!HasQuietVerbosity)
{
if (!HasQuietVerbosity) {
Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath));
}

Expand All @@ -146,15 +126,11 @@ private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel
try
{
var launchSettingsFileContents = File.ReadAllText(launchSettingsPath);
var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, LaunchProfile);
var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref targetCommand, LaunchProfile);
if (!applyResult.Success)
{
Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red());
}
else
{
launchSettingsModel = applyResult.LaunchSettings;
}
}
catch (IOException ex)
{
Expand All @@ -179,7 +155,7 @@ private void EnsureProjectIsBuilt()
new RestoringCommand(
restoreArgs.Prepend(Project),
restoreArgs,
new[] { Project },
new [] { Project },
NoRestore
).Execute();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
<target state="translated">Hodnotu vlastnosti {0} nejde převést na řetězec.</target>
<note />
</trans-unit>
<trans-unit id="RunCommandBuilding">
<source>Building...</source>
<target state="new">Building...</target>
<note />
</trans-unit>
<trans-unit id="RunCommandException">
<source>The build failed. Fix the build errors and run again.</source>
<target state="translated">Sestavení se nepovedlo. Opravte v sestavení chyby a spusťte ho znovu.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
<target state="translated">Der Wert der Eigenschaft "{0}" konnte nicht in eine Zeichenfolge konvertiert werden.</target>
<note />
</trans-unit>
<trans-unit id="RunCommandBuilding">
<source>Building...</source>
<target state="new">Building...</target>
<note />
</trans-unit>
<trans-unit id="RunCommandException">
<source>The build failed. Fix the build errors and run again.</source>
<target state="translated">Fehler beim Buildvorgang. Beheben Sie die Buildfehler, und versuchen Sie es anschließend noch mal.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
<target state="translated">No se pudo convertir el valor de la propiedad "{0}" en una cadena.</target>
<note />
</trans-unit>
<trans-unit id="RunCommandBuilding">
<source>Building...</source>
<target state="new">Building...</target>
<note />
</trans-unit>
<trans-unit id="RunCommandException">
<source>The build failed. Fix the build errors and run again.</source>
<target state="translated">No se pudo llevar a cabo la compilación. Corrija los errores de compilación y vuelva a ejecutar el proyecto.</target>
Expand Down
Loading