26
26
using System ;
27
27
using System . Collections . Concurrent ;
28
28
using System . Collections . Generic ;
29
+ using System . Diagnostics ;
29
30
using System . IO ;
30
31
using System . Linq ;
31
32
using System . Net ;
@@ -46,7 +47,7 @@ internal class LaunchProfileProvider
46
47
readonly object fileLocker = new object ( ) ;
47
48
public IDictionary < string , JToken > GlobalSettings { get ; private set ; }
48
49
internal JObject ProfilesObject { get ; private set ; }
49
- public ConcurrentDictionary < string , LaunchProfileData > Profiles { get ; set ; }
50
+ public ConcurrentDictionary < string , LaunchProfileData > Profiles { get ; private set ; }
50
51
internal string LaunchSettingsJsonPath => Path . Combine ( baseDirectory , "Properties" , "launchSettings.json" ) ;
51
52
const string DefaultGlobalSettings = @"{
52
53
""windowsAuthentication"": false,
@@ -58,12 +59,11 @@ internal class LaunchProfileProvider
58
59
59
60
public LaunchProfileData DefaultProfile {
60
61
get {
61
- if ( ! Profiles . ContainsKey ( defaultNamespace ) ) {
62
- var defaultProfile = CreateDefaultProfile ( ) ;
62
+ if ( ! Profiles . TryGetValue ( defaultNamespace , out var defaultProfile ) ) {
63
+ defaultProfile = CreateDefaultProfile ( ) ;
63
64
Profiles [ defaultNamespace ] = defaultProfile ;
64
- return defaultProfile ;
65
65
}
66
- return Profiles [ defaultNamespace ] ;
66
+ return defaultProfile ;
67
67
}
68
68
}
69
69
@@ -242,9 +242,7 @@ public LaunchProfileData AddNewProfile (string name)
242
242
if ( Profiles == null )
243
243
Profiles = new ConcurrentDictionary < string , LaunchProfileData > ( ) ;
244
244
245
- var newProfile = CreateProfile ( name ) ;
246
- Profiles [ name ] = newProfile ;
247
- return newProfile ;
245
+ return Profiles [ name ] = CreateProfile ( name ) ;
248
246
}
249
247
250
248
public LaunchProfileData CreateDefaultProfile ( ) => CreateProfile ( defaultNamespace ) ;
@@ -285,10 +283,8 @@ LaunchProfileData CreateProfile (string name)
285
283
void CreateAndAddDefaultLaunchSettings ( )
286
284
{
287
285
GlobalSettings . Add ( "iisSettings" , JToken . Parse ( DefaultGlobalSettings ) ) ;
288
- var profiles = new Dictionary < string , LaunchProfileData > {
289
- { defaultNamespace , CreateDefaultProfile ( ) }
290
- } ;
291
- Profiles = new ConcurrentDictionary < string , LaunchProfileData > ( profiles ) ;
286
+ Profiles = new ConcurrentDictionary < string , LaunchProfileData > ( ) ;
287
+ Profiles . TryAdd ( defaultNamespace , CreateDefaultProfile ( ) ) ;
292
288
SaveLaunchSettings ( ) ;
293
289
}
294
290
@@ -320,7 +316,11 @@ internal void SyncRunConfigurations ()
320
316
} else if ( runConfig is AspNetCoreRunConfiguration aspNetCoreRunConfiguration ) {
321
317
var index = project . RunConfigurations . IndexOf ( runConfig ) ;
322
318
aspNetCoreRunConfiguration . UpdateProfile ( profile . Value ) ;
323
- project . RunConfigurations [ index ] = runConfig ;
319
+ if ( index >= 0 ) {
320
+ project . RunConfigurations [ index ] = runConfig ;
321
+ }
322
+
323
+ Debug . Assert ( index >= 0 , "Didn't find expected run configuration" ) ;
324
324
}
325
325
}
326
326
@@ -333,7 +333,7 @@ internal void SyncRunConfigurations ()
333
333
key = project . DefaultNamespace ;
334
334
}
335
335
336
- if ( Profiles . TryGetValue ( key , out var _ ) )
336
+ if ( Profiles . TryGetValue ( key , out _ ) )
337
337
continue ;
338
338
339
339
itemsRemoved . Add ( config ) ;
0 commit comments