Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
2842612
Update dependencies from https://github.com/dotnet/fsharp build 20200…
dotnet-maestro[bot] Jul 24, 2020
f9e30fa
Update dependencies from https://github.com/dotnet/fsharp build 20200…
dotnet-maestro[bot] Jul 25, 2020
1133bf0
Update dependencies from https://github.com/dotnet/fsharp build 20200…
dotnet-maestro[bot] Jul 25, 2020
41e0418
Merge remote-tracking branch 'upstream/release/5.0.1xx-preview8' into…
sfoslund Jul 27, 2020
0058ea9
Fixing merge issues
sfoslund Jul 24, 2020
a50fb64
Revert Internal feeds for Preview 8 (#12556)
sfoslund Jul 24, 2020
3cade82
Update dependencies from https://github.com/dotnet/roslyn build 20200…
dotnet-maestro[bot] Jul 27, 2020
e5d8b6e
[release/5.0.1xx-preview8] Update dependencies from dotnet/roslyn (#1…
dotnet-maestro[bot] Jul 28, 2020
86d5bb3
Update dependencies from https://github.com/dotnet/roslyn build 20200…
dotnet-maestro[bot] Jul 28, 2020
5d93886
Merge pull request #12663 from dotnet/darc-release/5.0.1xx-preview8-3…
v-wuzhai Jul 28, 2020
2f0c5b3
[release/5.0.1xx-preview8] Update dependencies from dotnet/roslyn (#1…
dotnet-maestro[bot] Jul 28, 2020
911ac53
Update dependencies from https://github.com/dotnet/roslyn build 20200…
dotnet-maestro[bot] Jul 28, 2020
887b43d
Update dependencies from https://github.com/dotnet/msbuild build 2020…
dotnet-maestro[bot] Jul 28, 2020
ff7893d
Update dependencies from https://github.com/dotnet/msbuild build 2020…
dotnet-maestro[bot] Jul 29, 2020
5848f20
Merge pull request #12678 from dotnet/darc-release/5.0.1xx-preview8-1…
v-wuzhai Jul 29, 2020
ac76052
Update vstest to 16.8.0 in 5.0.1xx-preview8 (#12669)
nohwnd Jul 29, 2020
947b170
Update dependencies from https://github.com/dotnet/msbuild build 2020…
dotnet-maestro[bot] Jul 29, 2020
acaae38
Update dependencies from https://github.com/dotnet/roslyn build 20200…
dotnet-maestro[bot] Jul 29, 2020
0b1a5c5
Update dependencies from https://github.com/NuGet/NuGet.Client build …
dotnet-maestro[bot] Jul 30, 2020
1b99077
Update dependencies from https://github.com/microsoft/vstest build 20…
dotnet-maestro[bot] Jul 30, 2020
61992ab
Add modern --blame params to dotnet vstest and dotnet test + dll (#12…
nohwnd Jul 30, 2020
53b4184
Update dependencies from https://github.com/dotnet/msbuild build 2020…
dotnet-maestro[bot] Jul 30, 2020
89d3f30
Update dependencies from https://github.com/microsoft/vstest build 20…
dotnet-maestro[bot] Jul 30, 2020
0ede67e
Update dependencies from https://github.com/dotnet/msbuild build 2020…
dotnet-maestro[bot] Jul 31, 2020
a55e9e6
[release/5.0.1xx-preview8] Update dependencies from dotnet/msbuild (#…
dotnet-maestro[bot] Aug 3, 2020
4ff0664
Update dependencies from https://github.com/dotnet/msbuild build 2020…
dotnet-maestro[bot] Aug 3, 2020
c30f2d1
[release/5.0.1xx-preview8] Update dependencies from dotnet/msbuild (#…
dotnet-maestro[bot] Aug 4, 2020
9bdc52f
Merge remote-tracking branch 'upstream/release/5.0.1xx-preview8' into…
sfoslund Aug 4, 2020
fe2d181
Merge remote-tracking branch 'upstream/master' into mergePrev8
sfoslund Aug 5, 2020
f15a896
Clean up merge
sfoslund Aug 5, 2020
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:$false -vsRequirements:$GlobalJson.tools.'vs-opt'
$env:DOTNET_SDK_TEST_MSBUILD_PATH = InitializeVisualStudioMSBuild -install:$true -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: 3 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
]
},
"vs-opt": {
"version": "15.9"
}
"version": "16.8"
},
"xcopy-msbuild": "16.8.0-preview2"
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "5.0.0-beta.20374.1",
Expand Down
16 changes: 16 additions & 0 deletions src/Assets/TestProjects/TestAppWithLaunchSettings/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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;

namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello world");
Console.WriteLine($"MyCoolEnvironmentVariableKey={Environment.GetEnvironmentVariable("MyCoolEnvironmentVariableKey")}");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"profiles": {
"TestAppWithLaunchSettings": {
"commandName": "Project",
"dotnetRunMessages": "true",
"environmentVariables": {
"MyCoolEnvironmentVariableKey": "MyCoolEnvironmentVariableValue"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings
{
internal interface ILaunchSettingsProvider
{
string CommandName { get; }

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

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
// 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, string runAfterLaunch = null)
public LaunchSettingsApplyResult(bool success, string failureReason, ProjectLaunchSettingsModel launchSettings = null)
{
Success = success;
FailureReason = failureReason;
RunAfterLaunch = runAfterLaunch;
LaunchSettings = launchSettings;
}

public bool Success { get; }

public string FailureReason { get; }

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

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

return provider.TryApplySettings(profileObject, ref command);
return provider.TryGetLaunchSettings(profileObject);
}
}
catch (JsonException ex)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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.Collections.Generic;

namespace Microsoft.DotNet.Tools.Run.LaunchSettings
{
public class ProjectLaunchSettingsModel
{
public string CommandLineArgs { get; set; }

public bool LaunchBrowser { get; set; }

public string LaunchUrl { get; set; }

public string ApplicationUrl { get; set; }

public string DotNetRunMessages { get; set; }

public Dictionary<string, string> EnvironmentVariables { get; } = new Dictionary<string, string>(StringComparer.Ordinal);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System.Collections.Generic;
// 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.Text.Json;
using Microsoft.DotNet.Cli.Utils;

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

public string CommandName => CommandNameValue;

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

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 @@ -69,21 +79,7 @@ public LaunchSettingsApplyResult TryApplySettings(JsonElement model, ref IComman
}
}

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);
return new LaunchSettingsApplyResult(true, null, config);
}

private static bool TryGetBooleanValue(JsonElement element, out bool value)
Expand Down Expand Up @@ -136,23 +132,5 @@ 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: 4 additions & 1 deletion src/Cli/dotnet/commands/dotnet-run/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
<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 @@ -214,4 +217,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: 32 additions & 8 deletions src/Cli/dotnet/commands/dotnet-run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
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 @@ -41,17 +39,37 @@ 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 (!ApplyLaunchProfileSettingsIfNeeded(ref targetCommand))
if (launchSettings != null)
{
return 1;
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);
}
}

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

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

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

Expand All @@ -126,11 +146,15 @@ private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand)
try
{
var launchSettingsFileContents = File.ReadAllText(launchSettingsPath);
var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref targetCommand, LaunchProfile);
var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, 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 @@ -155,7 +179,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,6 +32,11 @@
<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,6 +32,11 @@
<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,6 +32,11 @@
<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