From 74bcc19431b5710f933606789bdbfb2ac6f9f04a Mon Sep 17 00:00:00 2001 From: mlorbetske Date: Tue, 30 May 2017 22:30:14 -0700 Subject: [PATCH] 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();