Remove NuGet.Configs, add inversion of the launch profile flag, move profile application logic to its own method
This commit is contained in:
parent
452e642ac7
commit
74bcc19431
4 changed files with 38 additions and 52 deletions
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="test-packages" value="../../../artifacts/testpackages" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="test-packages" value="../../../artifacts/testpackages" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="test-packages" value="../../../artifacts/testpackages" />
|
||||
</packageSources>
|
||||
</configuration>
|
|
@ -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<string> buildArgs = new List<string>();
|
||||
|
|
Loading…
Reference in a new issue