@@ -114,39 +114,40 @@ public static List<string> GetAudienceCandidatesFromLaunchSettings(string projec
114
114
ArgumentException . ThrowIfNullOrEmpty ( nameof ( project ) ) ;
115
115
116
116
var launchSettingsFilePath = Path . Combine ( Path . GetDirectoryName ( project ) ! , "Properties" , "launchSettings.json" ) ;
117
- var applicationUrls = new List < string > ( ) ;
117
+ var applicationUrls = new HashSet < string > ( ) ;
118
118
if ( File . Exists ( launchSettingsFilePath ) )
119
119
{
120
120
using var launchSettingsFileStream = new FileStream ( launchSettingsFilePath , FileMode . Open , FileAccess . Read ) ;
121
121
if ( launchSettingsFileStream . Length > 0 )
122
122
{
123
123
var launchSettingsJson = JsonDocument . Parse ( launchSettingsFileStream ) ;
124
+
125
+ if ( ExtractIISExpressUrlFromProfile ( launchSettingsJson . RootElement ) is { } iisUrls )
126
+ {
127
+ applicationUrls . UnionWith ( iisUrls ) ;
128
+ }
129
+
124
130
if ( launchSettingsJson . RootElement . TryGetProperty ( "profiles" , out var profiles ) )
125
131
{
126
132
var profilesEnumerator = profiles . EnumerateObject ( ) ;
127
133
foreach ( var profile in profilesEnumerator )
128
134
{
129
135
if ( ExtractKestrelUrlsFromProfile ( profile ) is { } kestrelUrls )
130
136
{
131
- applicationUrls . AddRange ( kestrelUrls ) ;
132
- }
133
-
134
- if ( ExtractIISExpressUrlFromProfile ( profile ) is { } iisUrls )
135
- {
136
- applicationUrls . AddRange ( iisUrls ) ;
137
+ applicationUrls . UnionWith ( kestrelUrls ) ;
137
138
}
138
139
}
139
140
}
140
141
}
141
142
}
142
143
143
- return applicationUrls ;
144
+ return applicationUrls . ToList ( ) ;
144
145
145
- static List < string > ExtractIISExpressUrlFromProfile ( JsonProperty profile )
146
+ static List < string > ExtractIISExpressUrlFromProfile ( JsonElement rootElement )
146
147
{
147
- if ( profile . NameEquals ( "iisSettings" ) )
148
+ if ( rootElement . TryGetProperty ( "iisSettings" , out var iisSettings ) )
148
149
{
149
- if ( profile . Value . TryGetProperty ( "iisExpress" , out var iisExpress ) )
150
+ if ( iisSettings . TryGetProperty ( "iisExpress" , out var iisExpress ) )
150
151
{
151
152
List < string > iisUrls = new ( ) ;
152
153
if ( iisExpress . TryGetProperty ( "applicationUrl" , out var iisUrl ) )
0 commit comments