@@ -25,7 +25,7 @@ public partial class RunCommand
2525
2626 public string LaunchProfile { get ; private set ; }
2727 public bool NoLaunchProfile { get ; private set ; }
28-
28+ private bool UseLaunchProfile => ! NoLaunchProfile ;
2929
3030 public int Start ( )
3131 {
@@ -37,39 +37,7 @@ public int Start()
3737 }
3838
3939 ICommand runCommand = GetRunCommand ( ) ;
40-
41- if ( ! NoLaunchProfile )
42- {
43- var buildPathContainer = File . Exists ( Project ) ? Path . GetDirectoryName ( Project ) : Project ;
44- var launchSettingsPath = Path . Combine ( buildPathContainer , "Properties" , "launchSettings.json" ) ;
45- if ( File . Exists ( launchSettingsPath ) )
46- {
47- Reporter . Output . WriteLine ( string . Format ( LocalizableStrings . UsingLaunchSettingsFromMessage , launchSettingsPath ) ) ;
48- string profileName = string . IsNullOrEmpty ( LaunchProfile ) ? LocalizableStrings . DefaultLaunchProfileDisplayName : LaunchProfile ;
49-
50- try
51- {
52- var launchSettingsFileContents = File . ReadAllText ( launchSettingsPath ) ;
53- var applyResult = LaunchSettingsManager . TryApplyLaunchSettings ( launchSettingsFileContents , ref runCommand , LaunchProfile ) ;
54- if ( ! applyResult . Success )
55- {
56- //Error that the launch profile couldn't be applied
57- Reporter . Error . WriteLine ( string . Format ( LocalizableStrings . RunCommandExceptionCouldNotApplyLaunchSettings , profileName , applyResult . FailureReason ) . Bold ( ) . Red ( ) ) ;
58- }
59- }
60- catch ( IOException ex )
61- {
62- Reporter . Error . WriteLine ( string . Format ( LocalizableStrings . RunCommandExceptionCouldNotApplyLaunchSettings , profileName ) . Bold ( ) . Red ( ) ) ;
63- Reporter . Error . WriteLine ( ex . Message . Bold ( ) . Red ( ) ) ;
64- return - 1 ;
65- }
66- }
67- else if ( ! string . IsNullOrEmpty ( LaunchProfile ) )
68- {
69- //Error that the launch profile couldn't be found
70- Reporter . Error . WriteLine ( LocalizableStrings . RunCommandExceptionCouldNotLocateALaunchSettingsFile . Bold ( ) . Red ( ) ) ;
71- }
72- }
40+ ApplyLaunchProfileSettingsIfNeeded ( ref runCommand ) ;
7341
7442 return runCommand
7543 . Execute ( )
@@ -112,6 +80,42 @@ public RunCommand MakeNewWithReplaced(string configuration = null,
11280 ) ;
11381 }
11482
83+ private void ApplyLaunchProfileSettingsIfNeeded ( ref ICommand runCommand )
84+ {
85+ if ( UseLaunchProfile )
86+ {
87+ var buildPathContainer = File . Exists ( Project ) ? Path . GetDirectoryName ( Project ) : Project ;
88+ var launchSettingsPath = Path . Combine ( buildPathContainer , "Properties" , "launchSettings.json" ) ;
89+ if ( File . Exists ( launchSettingsPath ) )
90+ {
91+ Reporter . Output . WriteLine ( string . Format ( LocalizableStrings . UsingLaunchSettingsFromMessage , launchSettingsPath ) ) ;
92+ string profileName = string . IsNullOrEmpty ( LaunchProfile ) ? LocalizableStrings . DefaultLaunchProfileDisplayName : LaunchProfile ;
93+
94+ try
95+ {
96+ var launchSettingsFileContents = File . ReadAllText ( launchSettingsPath ) ;
97+ var applyResult = LaunchSettingsManager . TryApplyLaunchSettings ( launchSettingsFileContents , ref runCommand , LaunchProfile ) ;
98+ if ( ! applyResult . Success )
99+ {
100+ //Error that the launch profile couldn't be applied
101+ Reporter . Error . WriteLine ( string . Format ( LocalizableStrings . RunCommandExceptionCouldNotApplyLaunchSettings , profileName , applyResult . FailureReason ) . Bold ( ) . Red ( ) ) ;
102+ }
103+ }
104+ catch ( IOException ex )
105+ {
106+ Reporter . Error . WriteLine ( string . Format ( LocalizableStrings . RunCommandExceptionCouldNotApplyLaunchSettings , profileName ) . Bold ( ) . Red ( ) ) ;
107+ Reporter . Error . WriteLine ( ex . Message . Bold ( ) . Red ( ) ) ;
108+ return - 1 ;
109+ }
110+ }
111+ else if ( ! string . IsNullOrEmpty ( LaunchProfile ) )
112+ {
113+ //Error that the launch profile couldn't be found
114+ Reporter . Error . WriteLine ( LocalizableStrings . RunCommandExceptionCouldNotLocateALaunchSettingsFile . Bold ( ) . Red ( ) ) ;
115+ }
116+ }
117+ }
118+
115119 private void EnsureProjectIsBuilt ( )
116120 {
117121 List < string > buildArgs = new List < string > ( ) ;
0 commit comments