From ed65b2bc9c4a548937c7c4477563be7fe4ce2448 Mon Sep 17 00:00:00 2001 From: John Beisner Date: Wed, 31 May 2017 08:35:00 -0700 Subject: [PATCH 01/13] Runtime download link missing the "runtime" identifier. --- scripts/obtain/dotnet-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/obtain/dotnet-install.sh b/scripts/obtain/dotnet-install.sh index b42d16c64..83ad96d17 100755 --- a/scripts/obtain/dotnet-install.sh +++ b/scripts/obtain/dotnet-install.sh @@ -398,7 +398,7 @@ construct_download_link() { local download_link=null if [ "$shared_runtime" = true ]; then - download_link="$azure_feed/Runtime/$specific_version/dotnet-$specific_version-$osname-$normalized_architecture.tar.gz" + download_link="$azure_feed/Runtime/$specific_version/dotnet-runtime-$specific_version-$osname-$normalized_architecture.tar.gz" else download_link="$azure_feed/Sdk/$specific_version/dotnet-dev-$specific_version-$osname-$normalized_architecture.tar.gz" fi From 20de0334e721166d9aaf33864548210fe9e6de76 Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Wed, 31 May 2017 11:40:30 -0700 Subject: [PATCH 02/13] Re-enable telemetry for new --- .../commands/dotnet-new/NewCommandShim.cs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/dotnet/commands/dotnet-new/NewCommandShim.cs b/src/dotnet/commands/dotnet-new/NewCommandShim.cs index 7dea29376..86f7b1574 100644 --- a/src/dotnet/commands/dotnet-new/NewCommandShim.cs +++ b/src/dotnet/commands/dotnet-new/NewCommandShim.cs @@ -31,13 +31,18 @@ namespace Microsoft.DotNet.Tools.New var sessionId = Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName); var telemetry = new Telemetry(new NuGetCacheSentinel(new CliFallbackFolderPathCalculator()), sessionId); var logger = new TelemetryLogger(null); - //(name, props, measures) => - //{ - // if (telemetry.Enabled) - // { - // telemetry.TrackEvent(name, props, measures); - // } - //}); + + if (telemetry.Enabled) + { + logger = new TelemetryLogger((name, props, measures) => + { + if (telemetry.Enabled) + { + telemetry.TrackEvent(name, props, measures); + } + }); + } + return New3Command.Run(CommandName, CreateHost(), logger, FirstRun, args); } From c28b454ecd167ce0a9f1790b93461822fd68e2e3 Mon Sep 17 00:00:00 2001 From: Mike Lorbetske Date: Wed, 31 May 2017 20:21:15 -0700 Subject: [PATCH 03/13] Update to SetupCrossgen 134 - Coherence 25332 --- build/DependencyVersions.props | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/build/DependencyVersions.props b/build/DependencyVersions.props index aee8b9cad..4603e7c40 100644 --- a/build/DependencyVersions.props +++ b/build/DependencyVersions.props @@ -13,9 +13,9 @@ $(CLI_SharedFrameworkVersion) $(CLI_SharedFrameworkVersion) $(CLI_SharedFrameworkVersion) - 1.0.0-beta2-20170523-241 - 1.0.0-beta2-20170526-244 - 1.0.0-beta2-20170526-244 + 1.0.0-beta2-20170531-247 + 1.0.0-beta2-20170531-247 + 1.0.0-beta2-20170531-247 2.0.0-preview2-25324-03 2.0.0-preview2-25324-03 0.1.0-alpha-142 @@ -24,8 +24,8 @@ timestamped - dev-128 - preview2-25179 + dev-134 + preview2-25332 From 2e100f7ed877160661595f36b21a1db7693581a7 Mon Sep 17 00:00:00 2001 From: Mike Lorbetske Date: Thu, 25 May 2017 18:47:59 -0700 Subject: [PATCH 04/13] Initial add of launchSettings.json support --- .../LaunchSettings/ILaunchSettingsProvider.cs | 13 +++ .../LaunchSettings/LaunchSettingsManager.cs | 96 +++++++++++++++++++ .../ProjectLaunchSettingsProvider.cs | 57 +++++++++++ .../commands/dotnet-run/LocalizableStrings.cs | 10 ++ src/dotnet/commands/dotnet-run/RunCommand.cs | 34 +++++++ .../commands/dotnet-run/RunCommandParser.cs | 10 ++ 6 files changed, 220 insertions(+) create mode 100644 src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs create mode 100644 src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs create mode 100644 src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs new file mode 100644 index 000000000..b860aa545 --- /dev/null +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs @@ -0,0 +1,13 @@ +using Microsoft.DotNet.Cli.Utils; +using Newtonsoft.Json.Linq; + +namespace Microsoft.DotNet.Tools.Run.LaunchSettings +{ + public interface ILaunchSettingsProvider + { + string CommandName { get; } + + bool TryApplySettings(JObject document, JObject model, ref ICommand command, out string runAfterLaunch); + } + +} diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs new file mode 100644 index 000000000..64fba9446 --- /dev/null +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs @@ -0,0 +1,96 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.DotNet.Cli.Utils; +using Newtonsoft.Json.Linq; + +namespace Microsoft.DotNet.Tools.Run.LaunchSettings +{ + internal class LaunchSettingsManager + { + private const string ProfilesKey = "profiles"; + private const string CommandNameKey = "commandName"; + private const string DefaultProfileCommandName = "Project"; + private static IReadOnlyDictionary _providers; + + static LaunchSettingsManager() + { + _providers = new Dictionary + { + { ProjectLaunchSettingsProvider.CommandNameValue, new ProjectLaunchSettingsProvider() } + }; + } + + public static bool TryApplyLaunchSettings(string launchSettingsJsonContents, ref ICommand command, out string runAfterLaunch, string profileName = null) + { + try + { + var model = JObject.Parse(launchSettingsJsonContents); + var profilesObject = model[ProfilesKey] as JObject; + + if (profilesObject == null) + { + runAfterLaunch = null; + return false; + } + + JObject profileObject; + if (profileName == null) + { + profileObject = profilesObject + .Properties() + .FirstOrDefault(IsDefaultProfileType)?.Value as JObject; + } + else + { + profileObject = profilesObject[profileName] as JObject; + } + + if (profileObject == null) + { + foreach (var prop in profilesObject.Properties()) + { + var profile = prop.Value as JObject; + + if (profile != null) + { + var cmdName = profile[CommandNameKey]?.Value(); + if (_providers.ContainsKey(cmdName)) + { + profileObject = profile; + break; + } + } + } + } + + var commandName = profileObject?[CommandNameKey]?.Value(); + + if (profileObject == null || !TryLocateHandler(commandName, out ILaunchSettingsProvider provider)) + { + runAfterLaunch = null; + return false; + } + + return provider.TryApplySettings(model, profileObject, ref command, out runAfterLaunch); + } + catch + { + runAfterLaunch = null; + return false; + } + } + + private static bool TryLocateHandler(string commandName, out ILaunchSettingsProvider provider) + { + return _providers.TryGetValue(commandName, out provider); + } + + private static bool IsDefaultProfileType(JProperty profileProperty) + { + JObject profile = profileProperty.Value as JObject; + var commandName = profile?[CommandNameKey]?.Value(); + return string.Equals(commandName, DefaultProfileCommandName, StringComparison.Ordinal); + } + } +} diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs new file mode 100644 index 000000000..905c4925a --- /dev/null +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using Microsoft.DotNet.Cli.Utils; +using Newtonsoft.Json.Linq; + +namespace Microsoft.DotNet.Tools.Run.LaunchSettings +{ + public class ProjectLaunchSettingsProvider : ILaunchSettingsProvider + { + public static readonly string CommandNameValue = "Project"; + + public string CommandName => CommandNameValue; + + public bool TryApplySettings(JObject document, JObject model, ref ICommand command, out string runAfterLaunch) + { + try + { + var config = model.ToObject(); + + //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); + } + + runAfterLaunch = null; + return true; + } + catch + { + runAfterLaunch = null; + return false; + } + } + + private class ProjectLaunchSettingsModel + { + public ProjectLaunchSettingsModel() + { + EnvironmentVariables = new Dictionary(); + } + + public string CommandLineArgs { get; set; } + + public bool LaunchBrowser { get; set; } + + public string LaunchUrl { get; set; } + + public string ApplicationUrl { get; set; } + + public Dictionary EnvironmentVariables { get; } + } + } +} diff --git a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs index 4cdfd5217..5664f8b11 100644 --- a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs @@ -17,6 +17,10 @@ namespace Microsoft.DotNet.Tools.Run public const string CommandOptionProjectDescription = "The path to the project file to run (defaults to the current directory if there is only one project)."; + public const string CommandOptionLaunchProfileDescription = "The name of the launch profile (if any) to use when launching the application."; + + public const string CommandOptionNoLaunchProfileDescription = "Do not attempt to use launchSettings.json to configure the application."; + public const string RunCommandException = "The build failed. Please fix the build errors and run again."; public const string RunCommandExceptionUnableToRunSpecifyFramework = "Unable to run your project\nYour project targets multiple frameworks. Please specify which framework to run using '{0}'."; @@ -28,5 +32,11 @@ namespace Microsoft.DotNet.Tools.Run public const string RunCommandExceptionMultipleProjects = "Specify which project file to use because {0} contains more than one project file."; public const string RunCommandAdditionalArgsHelpText = "Arguments passed to the application that is being run."; + + public const string RunCommandExceptionCouldNotLocateALaunchSettingsFile = "The specified launch profile could not be located."; + + public const string RunCommandExceptionCouldNotApplyLaunchSettings = "The launch profile \"{0}\" could not be applied."; + + public const string DefaultLaunchProfileDisplayName = "(Default)"; } } diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 5a60765ee..7b7d198e5 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -8,6 +8,7 @@ using System.Linq; using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.MSBuild; +using Microsoft.DotNet.Tools.Run.LaunchSettings; namespace Microsoft.DotNet.Tools.Run { @@ -22,6 +23,10 @@ namespace Microsoft.DotNet.Tools.Run private List _args; private bool ShouldBuild => !NoBuild; + public string LaunchProfile { get; private set; } + public bool NoLaunchProfile { get; private set; } + + public int Start() { Initialize(); @@ -33,6 +38,27 @@ namespace Microsoft.DotNet.Tools.Run ICommand runCommand = GetRunCommand(); + if (!NoLaunchProfile) + { + var buildPathContainer = File.Exists(Project) ? Path.GetDirectoryName(Project) : Project; + var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json"); + if (File.Exists(launchSettingsPath)) + { + var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); + if (!LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref runCommand, out string runAfterLaunch, LaunchProfile)) + { + string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile; + //Error that the launch profile couldn't be applied + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName)); + } + } + else if (!string.IsNullOrEmpty(LaunchProfile)) + { + //Error that the launch profile couldn't be found + Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile); + } + } + return runCommand .Execute() .ExitCode; @@ -42,12 +68,16 @@ namespace Microsoft.DotNet.Tools.Run string framework, bool noBuild, string project, + string launchProfile, + bool noLaunchProfile, IReadOnlyCollection args) { Configuration = configuration; Framework = framework; NoBuild = noBuild; Project = project; + LaunchProfile = launchProfile; + NoLaunchProfile = noLaunchProfile; Args = args; } @@ -55,6 +85,8 @@ namespace Microsoft.DotNet.Tools.Run string framework = null, bool? noBuild = null, string project = null, + string launchProfile = null, + bool? noLaunchProfile = null, IReadOnlyCollection args = null) { return new RunCommand( @@ -62,6 +94,8 @@ namespace Microsoft.DotNet.Tools.Run framework ?? this.Framework, noBuild ?? this.NoBuild, project ?? this.Project, + launchProfile ?? this.LaunchProfile, + noLaunchProfile ?? this.NoLaunchProfile, args ?? this.Args ); } diff --git a/src/dotnet/commands/dotnet-run/RunCommandParser.cs b/src/dotnet/commands/dotnet-run/RunCommandParser.cs index 54f439d79..ec0839c88 100644 --- a/src/dotnet/commands/dotnet-run/RunCommandParser.cs +++ b/src/dotnet/commands/dotnet-run/RunCommandParser.cs @@ -21,6 +21,8 @@ namespace Microsoft.DotNet.Cli framework: o.SingleArgumentOrDefault("--framework"), noBuild: o.HasOption("--no-build"), project: o.SingleArgumentOrDefault("--project"), + launchProfile: o.SingleArgumentOrDefault("--launch-profile"), + noLaunchProfile: o.HasOption("--no-launch-profile"), args: o.Arguments )), options: new[] @@ -32,6 +34,14 @@ namespace Microsoft.DotNet.Cli "-p|--project", LocalizableStrings.CommandOptionProjectDescription, Accept.ExactlyOneArgument()), + Create.Option( + "--launch-profile", + LocalizableStrings.CommandOptionLaunchProfileDescription, + Accept.ExactlyOneArgument()), + Create.Option( + "--no-launch-profile", + LocalizableStrings.CommandOptionNoLaunchProfileDescription, + Accept.NoArguments()), Create.Option( "--no-build", LocalizableStrings.CommandOptionNoBuildDescription, From 265da2064d05979498751739c12da3605cb1d9d4 Mon Sep 17 00:00:00 2001 From: Mike Lorbetske Date: Thu, 25 May 2017 20:53:03 -0700 Subject: [PATCH 05/13] Ad tests, fix issue where profile not found isn't an error --- ...dTestAppWithCorruptedLaunchSettings.csproj | 14 + .../NuGet.Config | 6 + .../Program.cs | 26 ++ .../MSBuildTestAppWithLaunchSettings.csproj | 14 + .../NuGet.Config | 6 + .../Program.cs | 26 ++ ...AppWithLaunchSettingsWithoutDefault.csproj | 14 + .../NuGet.Config | 6 + .../Program.cs | 26 ++ .../LaunchSettings/LaunchSettingsManager.cs | 6 + .../GivenDotnetRunRunsCsProj.cs | 263 ++++++++++++++++++ 11 files changed, 407 insertions(+) create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Program.cs create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Program.cs create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Program.cs diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj new file mode 100644 index 000000000..79bceb82d --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj @@ -0,0 +1,14 @@ + + + + + Exe + netcoreapp2.0 + win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 + + + + + + + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config new file mode 100644 index 000000000..b283135ce --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Program.cs b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Program.cs new file mode 100644 index 000000000..042e99826 --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Program.cs @@ -0,0 +1,26 @@ +// 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 MSBuildTestApp +{ + public class Program + { + public static void Main(string[] args) + { + if (args.Length > 0) + { + Console.WriteLine("echo args:" + string.Join(";", args)); + } + string message = Environment.GetEnvironmentVariable("Message"); + + if (string.IsNullOrEmpty(message)) + { + message = "(NO MESSAGE)"; + } + + Console.WriteLine(message); + } + } +} diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj new file mode 100644 index 000000000..79bceb82d --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj @@ -0,0 +1,14 @@ + + + + + Exe + netcoreapp2.0 + win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 + + + + + + + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config new file mode 100644 index 000000000..b283135ce --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Program.cs b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Program.cs new file mode 100644 index 000000000..042e99826 --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Program.cs @@ -0,0 +1,26 @@ +// 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 MSBuildTestApp +{ + public class Program + { + public static void Main(string[] args) + { + if (args.Length > 0) + { + Console.WriteLine("echo args:" + string.Join(";", args)); + } + string message = Environment.GetEnvironmentVariable("Message"); + + if (string.IsNullOrEmpty(message)) + { + message = "(NO MESSAGE)"; + } + + Console.WriteLine(message); + } + } +} diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj new file mode 100644 index 000000000..79bceb82d --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj @@ -0,0 +1,14 @@ + + + + + Exe + netcoreapp2.0 + win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 + + + + + + + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config new file mode 100644 index 000000000..b283135ce --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Program.cs b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Program.cs new file mode 100644 index 000000000..042e99826 --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Program.cs @@ -0,0 +1,26 @@ +// 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 MSBuildTestApp +{ + public class Program + { + public static void Main(string[] args) + { + if (args.Length > 0) + { + Console.WriteLine("echo args:" + string.Join(";", args)); + } + string message = Environment.GetEnvironmentVariable("Message"); + + if (string.IsNullOrEmpty(message)) + { + message = "(NO MESSAGE)"; + } + + Console.WriteLine(message); + } + } +} diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs index 64fba9446..6f76fa5b1 100644 --- a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs @@ -44,6 +44,12 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings else { profileObject = profilesObject[profileName] as JObject; + + if (profileObject == null) + { + runAfterLaunch = null; + return false; + } } if (profileObject == null) diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index 8ce1730be..49cf9c3fe 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -2,6 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.IO; +using FluentAssertions; using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; @@ -200,5 +201,267 @@ namespace Microsoft.DotNet.Cli.Run.Tests .Pass() .And.HaveStdOutContaining("echo args:foo;bar;baz"); } + + [Fact] + public void ItGivesAnErrorWhenAttemptingToUseALaunchProfileThatDoesNotExistWhenThereIsNoLaunchSettingsFile() + { + var testAppName = "MSBuildTestApp"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("--launch-profile test") + .Should().Pass() + .And.HaveStdOutContaining("Hello World!") + .And.HaveStdErrContaining("The specified launch profile could not be located."); + } + + [Fact] + public void ItUsesLaunchProfileOfTheSpecifiedName() + { + var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + var cmd = new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("--launch-profile Second"); + + cmd.Should().Pass() + .And.HaveStdOutContaining("Second"); + + cmd.StdErr.Should().BeEmpty(); + } + + [Fact] + public void ItDefaultsToTheFirstUsableLaunchProfile() + { + var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + var cmd = new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput(); + + cmd.Should().Pass() + .And.HaveStdOutContaining("First"); + + cmd.StdErr.Should().BeEmpty(); + } + + [Fact] + public void ItGivesAnErrorWhenTheLaunchProfileNotFound() + { + var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("--launch-profile Third") + .Should().Pass() + .And.HaveStdOutContaining("(NO MESSAGE)") + .And.HaveStdErrContaining("The launch profile \"Third\" could not be applied."); + } + + [Fact] + public void ItGivesAnErrorWhenTheLaunchProfileCanNotBeHandled() + { + var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("--launch-profile \"IIS Express\"") + .Should().Pass() + .And.HaveStdOutContaining("(NO MESSAGE)") + .And.HaveStdErrContaining("The launch profile \"IIS Express\" could not be applied."); + } + + [Fact] + public void ItSkipsLaunchProfilesWhenTheSwitchIsSupplied() + { + var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + var cmd = new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("--no-launch-profile"); + + cmd.Should().Pass() + .And.HaveStdOutContaining("(NO MESSAGE)"); + + cmd.StdErr.Should().BeEmpty(); + } + + [Fact] + public void ItSkipsLaunchProfilesWhenTheSwitchIsSuppliedWithoutErrorWhenThereAreNoLaunchSettings() + { + var testAppName = "MSBuildTestApp"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + var cmd = new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput("--no-launch-profile"); + + cmd.Should().Pass() + .And.HaveStdOutContaining("Hello World!"); + + cmd.StdErr.Should().BeEmpty(); + } + + [Fact] + public void ItSkipsLaunchProfilesWhenThereIsNoUsableDefault() + { + var testAppName = "MSBuildTestAppWithLaunchSettingsWithoutDefault"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + var cmd = new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput(); + + cmd.Should().Pass() + .And.HaveStdOutContaining("(NO MESSAGE)") + .And.HaveStdErrContaining("The launch profile \"(Default)\" could not be applied."); + } + + [Fact] + public void ItPrintsAnErrorWhenLaunchSettingsArCorrupted() + { + var testAppName = "MSBuildTestAppWithCorruptedLaunchSettings"; + var testInstance = TestAssets.Get(testAppName) + .CreateInstance() + .WithSourceFiles(); + + var testProjectDirectory = testInstance.Root.FullName; + + new RestoreCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute("/p:SkipInvalidConfigurations=true") + .Should().Pass(); + + new BuildCommand() + .WithWorkingDirectory(testProjectDirectory) + .Execute() + .Should().Pass(); + + var cmd = new RunCommand() + .WithWorkingDirectory(testProjectDirectory) + .ExecuteWithCapturedOutput(); + + cmd.Should().Pass() + .And.HaveStdOutContaining("(NO MESSAGE)") + .And.HaveStdErrContaining("The launch profile \"(Default)\" could not be applied."); + } } } From 7ebbef429390774366752a01fabe41bc879fd77a Mon Sep 17 00:00:00 2001 From: Mike Lorbetske Date: Thu, 25 May 2017 23:55:43 -0700 Subject: [PATCH 06/13] Add missed launch settings, fix NuGet.configs, remove unused packages --- ...dTestAppWithCorruptedLaunchSettings.csproj | 5 --- .../NuGet.Config | 2 +- .../Properties/launchSettings.json | 29 +++++++++++++++++ .../MSBuildTestAppWithLaunchSettings.csproj | 5 --- .../NuGet.Config | 2 +- .../Properties/launchSettings.json | 31 +++++++++++++++++++ ...AppWithLaunchSettingsWithoutDefault.csproj | 5 --- .../NuGet.Config | 2 +- .../Properties/launchSettings.json | 19 ++++++++++++ 9 files changed, 82 insertions(+), 18 deletions(-) create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Properties/launchSettings.json create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Properties/launchSettings.json create mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj index 79bceb82d..45a048433 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj +++ b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj @@ -6,9 +6,4 @@ netcoreapp2.0 win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 - - - - - diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config index b283135ce..b8e876fcb 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config +++ b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config @@ -1,6 +1,6 @@ - + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Properties/launchSettings.json b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Properties/launchSettings.json new file mode 100644 index 000000000..4307944ab --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49850/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "First": { + "commandName": "Project", + "environmentVariables": [ ] + }, + "Second": { + "commandName": "Project", + "environmentVariables": { + "Message": "Second" + } + } + } +} \ No newline at end of file diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj index 79bceb82d..45a048433 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj @@ -6,9 +6,4 @@ netcoreapp2.0 win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 - - - - - diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config index b283135ce..b8e876fcb 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config @@ -1,6 +1,6 @@ - + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Properties/launchSettings.json b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Properties/launchSettings.json new file mode 100644 index 000000000..615a345f2 --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49850/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "First": { + "commandName": "Project", + "environmentVariables": { + "Message": "First" + } + }, + "Second": { + "commandName": "Project", + "environmentVariables": { + "Message": "Second" + } + } + } +} \ No newline at end of file diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj index 79bceb82d..45a048433 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj @@ -6,9 +6,4 @@ netcoreapp2.0 win7-x64;win7-x86;osx.10.12-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;ubuntu.16.10-x64;centos.7-x64;rhel.7-x64;debian.8-x64;fedora.24-x64;opensuse.42.1-x64 - - - - - diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config index b283135ce..b8e876fcb 100644 --- a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config @@ -1,6 +1,6 @@ - + diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json new file mode 100644 index 000000000..010893fd5 --- /dev/null +++ b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json @@ -0,0 +1,19 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:49850/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} \ No newline at end of file From fc8428681e9ec88659f963abf25973c8c783a35a Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Mon, 29 May 2017 12:54:19 -0700 Subject: [PATCH 07/13] Make errors more specific, add support for setting the launch URL for ASP.NET apps --- .../LaunchSettings/ILaunchSettingsProvider.cs | 2 +- .../LaunchSettingsApplyResult.cs | 18 +++++++++++++ .../LaunchSettings/LaunchSettingsManager.cs | 25 ++++++++++--------- .../ProjectLaunchSettingsProvider.cs | 15 ++++++----- .../commands/dotnet-run/LocalizableStrings.cs | 14 ++++++++++- src/dotnet/commands/dotnet-run/RunCommand.cs | 24 +++++++++++++----- .../GivenDotnetRunRunsCsProj.cs | 2 +- 7 files changed, 73 insertions(+), 27 deletions(-) create mode 100644 src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs index b860aa545..64840872e 100644 --- a/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/ILaunchSettingsProvider.cs @@ -7,7 +7,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings { string CommandName { get; } - bool TryApplySettings(JObject document, JObject model, ref ICommand command, out string runAfterLaunch); + LaunchSettingsApplyResult TryApplySettings(JObject document, JObject model, ref ICommand command); } } diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs new file mode 100644 index 000000000..04b9dca3b --- /dev/null +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsApplyResult.cs @@ -0,0 +1,18 @@ +namespace Microsoft.DotNet.Tools.Run.LaunchSettings +{ + public class LaunchSettingsApplyResult + { + public LaunchSettingsApplyResult(bool success, string failureReason, string runAfterLaunch = null) + { + Success = success; + FailureReason = failureReason; + RunAfterLaunch = runAfterLaunch; + } + + public bool Success { get; } + + public string FailureReason { get; } + + public string RunAfterLaunch { get; } + } +} diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs index 6f76fa5b1..8246e820c 100644 --- a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs @@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings }; } - public static bool TryApplyLaunchSettings(string launchSettingsJsonContents, ref ICommand command, out string runAfterLaunch, string profileName = null) + public static LaunchSettingsApplyResult TryApplyLaunchSettings(string launchSettingsJsonContents, ref ICommand command, string profileName = null) { try { @@ -30,8 +30,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings if (profilesObject == null) { - runAfterLaunch = null; - return false; + return new LaunchSettingsApplyResult(false, LocalizableStrings.LaunchProfilesCollectionIsNotAJsonObject); } JObject profileObject; @@ -47,8 +46,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings if (profileObject == null) { - runAfterLaunch = null; - return false; + return new LaunchSettingsApplyResult(false, LocalizableStrings.LaunchProfileIsNotAJsonObject); } } @@ -72,18 +70,21 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings var commandName = profileObject?[CommandNameKey]?.Value(); - if (profileObject == null || !TryLocateHandler(commandName, out ILaunchSettingsProvider provider)) + if (profileObject == null) { - runAfterLaunch = null; - return false; + return new LaunchSettingsApplyResult(false, LocalizableStrings.UsableLaunchProfileCannotBeLocated); } - return provider.TryApplySettings(model, profileObject, ref command, out runAfterLaunch); + if (!TryLocateHandler(commandName, out ILaunchSettingsProvider provider)) + { + return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.LaunchProfileHandlerCannotBeLocated, commandName)); + } + + return provider.TryApplySettings(model, profileObject, ref command); } - catch + catch (Exception ex) { - runAfterLaunch = null; - return false; + return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.UnexpectedExceptionProcessingLaunchSettings, ex.Message)); } } diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs index 905c4925a..033f04381 100644 --- a/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/ProjectLaunchSettingsProvider.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings public string CommandName => CommandNameValue; - public bool TryApplySettings(JObject document, JObject model, ref ICommand command, out string runAfterLaunch) + public LaunchSettingsApplyResult TryApplySettings(JObject document, JObject model, ref ICommand command) { try { @@ -26,13 +26,16 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings command.EnvironmentVariable(entry.Key, value); } - runAfterLaunch = null; - return true; + if (!string.IsNullOrEmpty(config.ApplicationUrl)) + { + command.EnvironmentVariable("ASPNETCORE_URLS", config.ApplicationUrl); + } + + return new LaunchSettingsApplyResult(true, null, config.LaunchUrl); } - catch + catch (Exception ex) { - runAfterLaunch = null; - return false; + return new LaunchSettingsApplyResult(false, ex.Message); } } diff --git a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs index 5664f8b11..7d0374957 100644 --- a/src/dotnet/commands/dotnet-run/LocalizableStrings.cs +++ b/src/dotnet/commands/dotnet-run/LocalizableStrings.cs @@ -35,8 +35,20 @@ namespace Microsoft.DotNet.Tools.Run public const string RunCommandExceptionCouldNotLocateALaunchSettingsFile = "The specified launch profile could not be located."; - public const string RunCommandExceptionCouldNotApplyLaunchSettings = "The launch profile \"{0}\" could not be applied."; + public const string RunCommandExceptionCouldNotApplyLaunchSettings = "The launch profile \"{0}\" could not be applied.\n{1}"; public const string DefaultLaunchProfileDisplayName = "(Default)"; + + public const string UsingLaunchSettingsFromMessage = "Using launch settings from {0}..."; + + public const string LaunchProfileIsNotAJsonObject = "Launch profile is not a JSON object."; + + public const string LaunchProfileHandlerCannotBeLocated = "The launch profile type '{0}' is not supported."; + + public const string UsableLaunchProfileCannotBeLocated = "A usable launch profile could not be located."; + + public const string UnexpectedExceptionProcessingLaunchSettings = "An unexpected exception occurred while processing launch settings:\n{0}"; + + public const string LaunchProfilesCollectionIsNotAJsonObject = "The 'profiles' property of the launch settings document is not a JSON object."; } } diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 7b7d198e5..87390c14f 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -44,18 +44,30 @@ namespace Microsoft.DotNet.Tools.Run var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json"); if (File.Exists(launchSettingsPath)) { - var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); - if (!LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref runCommand, out string runAfterLaunch, LaunchProfile)) + Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); + string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile; + + try { - string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile; - //Error that the launch profile couldn't be applied - Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName)); + var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); + var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref runCommand, LaunchProfile); + if (!applyResult.Success) + { + //Error that the launch profile couldn't be applied + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); + } + } + catch (IOException ex) + { + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName).Bold().Red()); + Reporter.Error.WriteLine(ex.Message.Bold().Red()); + return -1; } } else if (!string.IsNullOrEmpty(LaunchProfile)) { //Error that the launch profile couldn't be found - Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile); + Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile.Bold().Red()); } } diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index 49cf9c3fe..221267853 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -436,7 +436,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests } [Fact] - public void ItPrintsAnErrorWhenLaunchSettingsArCorrupted() + public void ItPrintsAnErrorWhenLaunchSettingsAreCorrupted() { var testAppName = "MSBuildTestAppWithCorruptedLaunchSettings"; var testInstance = TestAssets.Get(testAppName) From 85870a711ed56f29308f0c4e8dc9cd562ff860d7 Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Tue, 30 May 2017 22:30:14 -0700 Subject: [PATCH 08/13] Remove NuGet.Configs, add inversion of the launch profile flag, move profile application logic to its own method --- .../NuGet.Config | 6 -- .../NuGet.Config | 6 -- .../NuGet.Config | 6 -- src/dotnet/commands/dotnet-run/RunCommand.cs | 72 ++++++++++--------- 4 files changed, 38 insertions(+), 52 deletions(-) delete mode 100644 TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config delete mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config delete mode 100644 TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config deleted file mode 100644 index b8e876fcb..000000000 --- a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config deleted file mode 100644 index b8e876fcb..000000000 --- a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config b/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config deleted file mode 100644 index b8e876fcb..000000000 --- a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/NuGet.Config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 87390c14f..98fbfedc6 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Run public string LaunchProfile { get; private set; } public bool NoLaunchProfile { get; private set; } - + private bool UseLaunchProfile => !NoLaunchProfile; public int Start() { @@ -37,39 +37,7 @@ namespace Microsoft.DotNet.Tools.Run } ICommand runCommand = GetRunCommand(); - - if (!NoLaunchProfile) - { - var buildPathContainer = File.Exists(Project) ? Path.GetDirectoryName(Project) : Project; - var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json"); - if (File.Exists(launchSettingsPath)) - { - Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); - string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile; - - try - { - var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); - var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref runCommand, LaunchProfile); - if (!applyResult.Success) - { - //Error that the launch profile couldn't be applied - Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); - } - } - catch (IOException ex) - { - Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName).Bold().Red()); - Reporter.Error.WriteLine(ex.Message.Bold().Red()); - return -1; - } - } - else if (!string.IsNullOrEmpty(LaunchProfile)) - { - //Error that the launch profile couldn't be found - Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile.Bold().Red()); - } - } + ApplyLaunchProfileSettingsIfNeeded(ref runCommand); return runCommand .Execute() @@ -112,6 +80,42 @@ namespace Microsoft.DotNet.Tools.Run ); } + private void ApplyLaunchProfileSettingsIfNeeded(ref ICommand runCommand) + { + if (UseLaunchProfile) + { + var buildPathContainer = File.Exists(Project) ? Path.GetDirectoryName(Project) : Project; + var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json"); + if (File.Exists(launchSettingsPath)) + { + Reporter.Output.WriteLine(string.Format(LocalizableStrings.UsingLaunchSettingsFromMessage, launchSettingsPath)); + string profileName = string.IsNullOrEmpty(LaunchProfile) ? LocalizableStrings.DefaultLaunchProfileDisplayName : LaunchProfile; + + try + { + var launchSettingsFileContents = File.ReadAllText(launchSettingsPath); + var applyResult = LaunchSettingsManager.TryApplyLaunchSettings(launchSettingsFileContents, ref runCommand, LaunchProfile); + if (!applyResult.Success) + { + //Error that the launch profile couldn't be applied + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); + } + } + catch (IOException ex) + { + Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName).Bold().Red()); + Reporter.Error.WriteLine(ex.Message.Bold().Red()); + return -1; + } + } + else if (!string.IsNullOrEmpty(LaunchProfile)) + { + //Error that the launch profile couldn't be found + Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile.Bold().Red()); + } + } + } + private void EnsureProjectIsBuilt() { List buildArgs = new List(); From bcb12a69f434d3b9b72cacb71ce1d29f3ce20b69 Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Tue, 30 May 2017 22:42:24 -0700 Subject: [PATCH 09/13] Fix flow from the refactoring --- src/dotnet/commands/dotnet-run/RunCommand.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-run/RunCommand.cs b/src/dotnet/commands/dotnet-run/RunCommand.cs index 98fbfedc6..3401f1ac1 100644 --- a/src/dotnet/commands/dotnet-run/RunCommand.cs +++ b/src/dotnet/commands/dotnet-run/RunCommand.cs @@ -37,7 +37,12 @@ namespace Microsoft.DotNet.Tools.Run } ICommand runCommand = GetRunCommand(); - ApplyLaunchProfileSettingsIfNeeded(ref runCommand); + int launchSettingsApplicationResult = ApplyLaunchProfileSettingsIfNeeded(ref runCommand); + + if (launchSettingsApplicationResult != 0) + { + return launchSettingsApplicationResult; + } return runCommand .Execute() @@ -80,7 +85,7 @@ namespace Microsoft.DotNet.Tools.Run ); } - private void ApplyLaunchProfileSettingsIfNeeded(ref ICommand runCommand) + private int ApplyLaunchProfileSettingsIfNeeded(ref ICommand runCommand) { if (UseLaunchProfile) { @@ -114,6 +119,8 @@ namespace Microsoft.DotNet.Tools.Run Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile.Bold().Red()); } } + + return 0; } private void EnsureProjectIsBuilt() From e6527bf3ef9f1bf043b622803af1ecf904ee14ae Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Wed, 31 May 2017 11:48:01 -0700 Subject: [PATCH 10/13] Shorten test project names --- ...SBuildTestAppWithCorruptedLaunchSettings.csproj | 0 .../Program.cs | 0 .../Properties/launchSettings.json | 0 .../MSBuildTestAppWithLaunchSettings.csproj | 0 .../Program.cs | 0 .../Properties/launchSettings.json | 0 ...dTestAppWithLaunchSettingsWithoutDefault.csproj | 0 .../Program.cs | 0 .../Properties/launchSettings.json | 0 test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs | 14 +++++++------- 10 files changed, 7 insertions(+), 7 deletions(-) rename TestAssets/TestProjects/{MSBuildTestAppWithCorruptedLaunchSettings => AppWithCorruptedLaunchSettings}/MSBuildTestAppWithCorruptedLaunchSettings.csproj (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithCorruptedLaunchSettings => AppWithCorruptedLaunchSettings}/Program.cs (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithCorruptedLaunchSettings => AppWithCorruptedLaunchSettings}/Properties/launchSettings.json (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithLaunchSettings => AppWithLaunchSettings}/MSBuildTestAppWithLaunchSettings.csproj (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithLaunchSettings => AppWithLaunchSettings}/Program.cs (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithLaunchSettings => AppWithLaunchSettings}/Properties/launchSettings.json (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithLaunchSettingsWithoutDefault => AppWithLaunchSettingsWithoutDefault}/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithLaunchSettingsWithoutDefault => AppWithLaunchSettingsWithoutDefault}/Program.cs (100%) rename TestAssets/TestProjects/{MSBuildTestAppWithLaunchSettingsWithoutDefault => AppWithLaunchSettingsWithoutDefault}/Properties/launchSettings.json (100%) diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj b/TestAssets/TestProjects/AppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj rename to TestAssets/TestProjects/AppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Program.cs b/TestAssets/TestProjects/AppWithCorruptedLaunchSettings/Program.cs similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Program.cs rename to TestAssets/TestProjects/AppWithCorruptedLaunchSettings/Program.cs diff --git a/TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Properties/launchSettings.json b/TestAssets/TestProjects/AppWithCorruptedLaunchSettings/Properties/launchSettings.json similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithCorruptedLaunchSettings/Properties/launchSettings.json rename to TestAssets/TestProjects/AppWithCorruptedLaunchSettings/Properties/launchSettings.json diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj b/TestAssets/TestProjects/AppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj rename to TestAssets/TestProjects/AppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Program.cs b/TestAssets/TestProjects/AppWithLaunchSettings/Program.cs similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Program.cs rename to TestAssets/TestProjects/AppWithLaunchSettings/Program.cs diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Properties/launchSettings.json b/TestAssets/TestProjects/AppWithLaunchSettings/Properties/launchSettings.json similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithLaunchSettings/Properties/launchSettings.json rename to TestAssets/TestProjects/AppWithLaunchSettings/Properties/launchSettings.json diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj b/TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj rename to TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Program.cs b/TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Program.cs similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Program.cs rename to TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Program.cs diff --git a/TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json b/TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json similarity index 100% rename from TestAssets/TestProjects/MSBuildTestAppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json rename to TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index 221267853..cc5195e48 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -233,7 +233,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItUsesLaunchProfileOfTheSpecifiedName() { - var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testAppName = "AppWithLaunchSettings"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); @@ -263,7 +263,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItDefaultsToTheFirstUsableLaunchProfile() { - var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testAppName = "AppWithLaunchSettings"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); @@ -293,7 +293,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItGivesAnErrorWhenTheLaunchProfileNotFound() { - var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testAppName = "AppWithLaunchSettings"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); @@ -321,7 +321,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItGivesAnErrorWhenTheLaunchProfileCanNotBeHandled() { - var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testAppName = "AppWithLaunchSettings"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); @@ -349,7 +349,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItSkipsLaunchProfilesWhenTheSwitchIsSupplied() { - var testAppName = "MSBuildTestAppWithLaunchSettings"; + var testAppName = "AppWithLaunchSettings"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); @@ -409,7 +409,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItSkipsLaunchProfilesWhenThereIsNoUsableDefault() { - var testAppName = "MSBuildTestAppWithLaunchSettingsWithoutDefault"; + var testAppName = "AppWithLaunchSettingsWithoutDefault"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); @@ -438,7 +438,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItPrintsAnErrorWhenLaunchSettingsAreCorrupted() { - var testAppName = "MSBuildTestAppWithCorruptedLaunchSettings"; + var testAppName = "AppWithCorruptedLaunchSettings"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); From 21cb95f05a4cbd9d9f4e576e7660e47c5cae1eef Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Wed, 31 May 2017 14:07:34 -0700 Subject: [PATCH 11/13] Shorten names a bit more, make project names match folder names --- ...nchSettings.csproj => AppWithCorruptedLaunchSettings.csproj} | 0 ...ppWithLaunchSettings.csproj => AppWithLaunchSettings.csproj} | 0 .../AppWithLaunchSettingsNoDefault.csproj} | 0 .../Program.cs | 0 .../Properties/launchSettings.json | 0 test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs | 2 +- 6 files changed, 1 insertion(+), 1 deletion(-) rename TestAssets/TestProjects/AppWithCorruptedLaunchSettings/{MSBuildTestAppWithCorruptedLaunchSettings.csproj => AppWithCorruptedLaunchSettings.csproj} (100%) rename TestAssets/TestProjects/AppWithLaunchSettings/{MSBuildTestAppWithLaunchSettings.csproj => AppWithLaunchSettings.csproj} (100%) rename TestAssets/TestProjects/{AppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj => AppWithLaunchSettingsNoDefault/AppWithLaunchSettingsNoDefault.csproj} (100%) rename TestAssets/TestProjects/{AppWithLaunchSettingsWithoutDefault => AppWithLaunchSettingsNoDefault}/Program.cs (100%) rename TestAssets/TestProjects/{AppWithLaunchSettingsWithoutDefault => AppWithLaunchSettingsNoDefault}/Properties/launchSettings.json (100%) diff --git a/TestAssets/TestProjects/AppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj b/TestAssets/TestProjects/AppWithCorruptedLaunchSettings/AppWithCorruptedLaunchSettings.csproj similarity index 100% rename from TestAssets/TestProjects/AppWithCorruptedLaunchSettings/MSBuildTestAppWithCorruptedLaunchSettings.csproj rename to TestAssets/TestProjects/AppWithCorruptedLaunchSettings/AppWithCorruptedLaunchSettings.csproj diff --git a/TestAssets/TestProjects/AppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj b/TestAssets/TestProjects/AppWithLaunchSettings/AppWithLaunchSettings.csproj similarity index 100% rename from TestAssets/TestProjects/AppWithLaunchSettings/MSBuildTestAppWithLaunchSettings.csproj rename to TestAssets/TestProjects/AppWithLaunchSettings/AppWithLaunchSettings.csproj diff --git a/TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj b/TestAssets/TestProjects/AppWithLaunchSettingsNoDefault/AppWithLaunchSettingsNoDefault.csproj similarity index 100% rename from TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/MSBuildTestAppWithLaunchSettingsWithoutDefault.csproj rename to TestAssets/TestProjects/AppWithLaunchSettingsNoDefault/AppWithLaunchSettingsNoDefault.csproj diff --git a/TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Program.cs b/TestAssets/TestProjects/AppWithLaunchSettingsNoDefault/Program.cs similarity index 100% rename from TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Program.cs rename to TestAssets/TestProjects/AppWithLaunchSettingsNoDefault/Program.cs diff --git a/TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json b/TestAssets/TestProjects/AppWithLaunchSettingsNoDefault/Properties/launchSettings.json similarity index 100% rename from TestAssets/TestProjects/AppWithLaunchSettingsWithoutDefault/Properties/launchSettings.json rename to TestAssets/TestProjects/AppWithLaunchSettingsNoDefault/Properties/launchSettings.json diff --git a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs index cc5195e48..234f890e9 100644 --- a/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs +++ b/test/dotnet-run.Tests/GivenDotnetRunRunsCsProj.cs @@ -409,7 +409,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests [Fact] public void ItSkipsLaunchProfilesWhenThereIsNoUsableDefault() { - var testAppName = "AppWithLaunchSettingsWithoutDefault"; + var testAppName = "AppWithLaunchSettingsNoDefault"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles(); From 68f2d17034a4658b2b52358f7c585dd36a560167 Mon Sep 17 00:00:00 2001 From: Mike Lorbetske Date: Wed, 31 May 2017 23:12:07 -0700 Subject: [PATCH 12/13] Only catch JsonException in the method that dispatches to the appropriate handlers --- .../commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs index 8246e820c..a655bc285 100644 --- a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs @@ -82,7 +82,7 @@ namespace Microsoft.DotNet.Tools.Run.LaunchSettings return provider.TryApplySettings(model, profileObject, ref command); } - catch (Exception ex) + catch (JsonException ex) { return new LaunchSettingsApplyResult(false, string.Format(LocalizableStrings.UnexpectedExceptionProcessingLaunchSettings, ex.Message)); } From 052caa560c17146dee719f2d74740bd9919d0b71 Mon Sep 17 00:00:00 2001 From: Mike Lorbetske Date: Wed, 31 May 2017 23:31:42 -0700 Subject: [PATCH 13/13] Add missing using directive --- .../commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs index a655bc285..dd27329c6 100644 --- a/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs +++ b/src/dotnet/commands/dotnet-run/LaunchSettings/LaunchSettingsManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.Cli.Utils; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Microsoft.DotNet.Tools.Run.LaunchSettings