4
4
using System . Diagnostics . CodeAnalysis ;
5
5
using System . Globalization ;
6
6
using System . Text . Json ;
7
- using System . Text . Json . Serialization ;
8
7
using Aspire . Hosting . ApplicationModel ;
9
8
using Aspire . Hosting . Properties ;
10
9
@@ -29,7 +28,7 @@ internal static class LaunchProfileExtensions
29
28
return projectMetadata . GetLaunchSettings ( ) ;
30
29
}
31
30
32
- internal static LaunchProfile ? GetEffectiveLaunchProfile ( this ProjectResource projectResource , bool throwIfNotFound = false )
31
+ internal static NamedLaunchProfile ? GetEffectiveLaunchProfile ( this ProjectResource projectResource , bool throwIfNotFound = false )
33
32
{
34
33
string ? launchProfileName = projectResource . SelectLaunchProfileName ( ) ;
35
34
if ( string . IsNullOrEmpty ( launchProfileName ) )
@@ -49,7 +48,8 @@ internal static class LaunchProfileExtensions
49
48
var message = string . Format ( CultureInfo . InvariantCulture , Resources . LaunchSettingsFileDoesNotContainProfileExceptionMessage , launchProfileName ) ;
50
49
throw new DistributedApplicationException ( message ) ;
51
50
}
52
- return found == true ? launchProfile : null ;
51
+
52
+ return launchProfile is not null ? new ( launchProfileName , launchProfile ) : default ;
53
53
}
54
54
55
55
private static LaunchSettings ? GetLaunchSettings ( this IProjectMetadata projectMetadata )
@@ -87,7 +87,7 @@ internal static class LaunchProfileExtensions
87
87
private static readonly LaunchProfileSelector [ ] s_launchProfileSelectors =
88
88
[
89
89
TrySelectLaunchProfileFromAnnotation ,
90
- TrySelectLaunchProfileFromEnvironment ,
90
+ TrySelectLaunchProfileFromDefaultAnnotation ,
91
91
TrySelectLaunchProfileByOrder
92
92
] ;
93
93
@@ -105,31 +105,30 @@ private static bool TrySelectLaunchProfileByOrder(ProjectResource projectResourc
105
105
return true ;
106
106
}
107
107
108
- private static bool TrySelectLaunchProfileFromEnvironment ( ProjectResource projectResource , [ NotNullWhen ( true ) ] out string ? launchProfileName )
108
+ private static bool TrySelectLaunchProfileFromDefaultAnnotation ( ProjectResource projectResource , [ NotNullWhen ( true ) ] out string ? launchProfileName )
109
109
{
110
- var launchProfileEnvironmentVariable = Environment . GetEnvironmentVariable ( "DOTNET_LAUNCH_PROFILE" ) ;
111
-
112
- if ( launchProfileEnvironmentVariable is null )
110
+ if ( ! projectResource . TryGetLastAnnotation < DefaultLaunchProfileAnnotation > ( out var launchProfileAnnotation ) )
113
111
{
114
112
launchProfileName = null ;
115
113
return false ;
116
114
}
117
115
116
+ var appHostDefaultLaunchProfileName = launchProfileAnnotation . LaunchProfileName ;
118
117
var launchSettings = GetLaunchSettings ( projectResource ) ;
119
118
if ( launchSettings == null )
120
119
{
121
120
launchProfileName = null ;
122
121
return false ;
123
122
}
124
123
125
- if ( ! launchSettings . Profiles . TryGetValue ( launchProfileEnvironmentVariable , out var launchProfile ) )
124
+ if ( ! launchSettings . Profiles . TryGetValue ( appHostDefaultLaunchProfileName , out var launchProfile ) || launchProfile is null )
126
125
{
127
126
launchProfileName = null ;
128
127
return false ;
129
128
}
130
129
131
- launchProfileName = launchProfileEnvironmentVariable ;
132
- return launchProfile != null ;
130
+ launchProfileName = appHostDefaultLaunchProfileName ;
131
+ return true ;
133
132
}
134
133
135
134
private static bool TrySelectLaunchProfileFromAnnotation ( ProjectResource projectResource , [ NotNullWhen ( true ) ] out string ? launchProfileName )
@@ -166,11 +165,6 @@ private static bool TrySelectLaunchProfileFromAnnotation(ProjectResource project
166
165
}
167
166
}
168
167
169
- internal delegate bool LaunchProfileSelector ( ProjectResource project , out string ? launchProfile ) ;
170
-
171
- [ JsonSerializable ( typeof ( LaunchSettings ) ) ]
172
- [ JsonSourceGenerationOptions ( ReadCommentHandling = JsonCommentHandling . Skip ) ]
173
- internal sealed partial class LaunchSettingsSerializerContext : JsonSerializerContext
174
- {
168
+ internal sealed record class NamedLaunchProfile ( string Name , LaunchProfile LaunchProfile ) ;
175
169
176
- }
170
+ internal delegate bool LaunchProfileSelector ( ProjectResource project , out string ? launchProfile ) ;
0 commit comments