private bool TryGetLaunchProfileSettingsIfNeeded(out ProjectLaunchSettingsModel launchSettingsModel) { launchSettingsModel = default; if (!UseLaunchProfile) { return(true); } var buildPathContainer = File.Exists(Project) ? Path.GetDirectoryName(Project) : Project; string propsDirectory; // VB.NET projects store the launch settings file in the // "My Project" directory instead of a "Properties" directory. if (string.Equals(Path.GetExtension(Project), ".vbproj", StringComparison.OrdinalIgnoreCase)) { propsDirectory = "My Project"; } else { propsDirectory = "Properties"; } var launchSettingsPath = Path.Combine(buildPathContainer, propsDirectory, "launchSettings.json"); if (File.Exists(launchSettingsPath)) { if (!HasQuietVerbosity) { 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, LaunchProfile); if (!applyResult.Success) { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName, applyResult.FailureReason).Bold().Red()); } else { launchSettingsModel = applyResult.LaunchSettings; } } catch (IOException ex) { Reporter.Error.WriteLine(string.Format(LocalizableStrings.RunCommandExceptionCouldNotApplyLaunchSettings, profileName).Bold().Red()); Reporter.Error.WriteLine(ex.Message.Bold().Red()); return(false); } } else if (!string.IsNullOrEmpty(LaunchProfile)) { Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile.Bold().Red()); } return(true); }
private bool ApplyLaunchProfileSettingsIfNeeded(ref ICommand targetCommand) { if (!UseLaunchProfile) { return(true); } var buildPathContainer = File.Exists(Project) ? Path.GetDirectoryName(Project) : Project; var launchSettingsPath = Path.Combine(buildPathContainer, "Properties", "launchSettings.json"); if (File.Exists(launchSettingsPath)) { if (!HasQuietVerbosity) { 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 targetCommand, LaunchProfile); if (!applyResult.Success) { 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(false); } } else if (!string.IsNullOrEmpty(LaunchProfile)) { Reporter.Error.WriteLine(LocalizableStrings.RunCommandExceptionCouldNotLocateALaunchSettingsFile.Bold().Red()); } return(true); }