3
3
using System . Globalization ;
4
4
using System . IO ;
5
5
using System . Linq ;
6
- using System . Runtime . CompilerServices ;
7
6
using Amazon . Common . DotNetCli . Tools ;
8
7
using Amazon . ElasticBeanstalk . Model ;
9
8
using Amazon . ElasticBeanstalk . Tools . Commands ;
@@ -108,26 +107,24 @@ public static bool IsLoadBalancedEnvironmentType(string environmentType)
108
107
return string . Equals ( environmentType , EBConstants . ENVIRONMENT_TYPE_LOADBALANCED , StringComparison . OrdinalIgnoreCase ) ;
109
108
}
110
109
111
-
112
110
public static void SetupPackageForLinux ( IToolLogger logger , EBBaseCommand command , DeployEnvironmentProperties options , string publishLocation , string reverseProxy , int ? applicationPort )
113
111
{
114
112
// Setup Procfile
115
113
var procfilePath = Path . Combine ( publishLocation , "Procfile" ) ;
116
114
117
- if ( File . Exists ( procfilePath ) )
115
+ if ( File . Exists ( procfilePath ) )
118
116
{
119
117
logger ? . WriteLine ( "Found existing Procfile file found and using that for deployment" ) ;
120
118
return ;
121
119
}
122
120
123
121
logger ? . WriteLine ( "Writing Procfile for deployment bundle" ) ;
124
-
125
- var runtimeConfigFilePath = Directory . GetFiles ( publishLocation , "*.runtimeconfig.json" ) . FirstOrDefault ( ) ;
122
+ string runtimeConfigFilePath = GetRuntimeConfigFilePath ( publishLocation ) ;
126
123
var runtimeConfigFileName = Path . GetFileName ( runtimeConfigFilePath ) ;
127
124
var executingAssembly = runtimeConfigFileName . Substring ( 0 , runtimeConfigFileName . Length - "runtimeconfig.json" . Length - 1 ) ;
128
125
129
126
string webCommandLine ;
130
- if ( IsSelfContainedPublish ( runtimeConfigFilePath ) )
127
+ if ( IsSelfContainedPublish ( runtimeConfigFilePath ) )
131
128
{
132
129
webCommandLine = $ "./{ executingAssembly } ";
133
130
}
@@ -136,7 +133,7 @@ public static void SetupPackageForLinux(IToolLogger logger, EBBaseCommand comman
136
133
webCommandLine = $ "dotnet exec ./{ executingAssembly } .dll";
137
134
}
138
135
139
- if ( string . Equals ( reverseProxy , EBConstants . PROXY_SERVER_NONE , StringComparison . InvariantCulture ) )
136
+ if ( string . Equals ( reverseProxy , EBConstants . PROXY_SERVER_NONE , StringComparison . InvariantCulture ) )
140
137
{
141
138
logger ? . WriteLine ( "... Proxy server disabled, configuring Kestrel to listen to traffic from all hosts" ) ;
142
139
var port = applicationPort . HasValue ? applicationPort . Value : EBConstants . DEFAULT_APPLICATION_PORT ;
@@ -175,5 +172,65 @@ public static string FindExistingValue(this List<ConfigurationOptionSetting> set
175
172
var setting = settings ? . FirstOrDefault ( x => string . Equals ( x . Namespace , ns , StringComparison . InvariantCulture ) && string . Equals ( x . OptionName , name , StringComparison . InvariantCulture ) ) ;
176
173
return setting ? . Value ;
177
174
}
175
+
176
+ private static string GetRuntimeConfigFilePath ( string publishLocation )
177
+ {
178
+ var runtimeConfigFiles = Directory . GetFiles ( publishLocation , "*.runtimeconfig.json" ) ;
179
+
180
+ // Handle case where application could have multiple runtimeconfig.json files in publish location.
181
+ if ( runtimeConfigFiles . Length > 1 )
182
+ {
183
+ foreach ( var file in runtimeConfigFiles )
184
+ {
185
+ var fileContent = File . ReadAllText ( file ) ;
186
+
187
+ JsonData root = JsonMapper . ToObject ( fileContent ) ;
188
+ JsonData runtimeOptions = root [ "runtimeOptions" ] as JsonData ;
189
+ if ( runtimeOptions == null )
190
+ {
191
+ continue ;
192
+ }
193
+
194
+ // runtimeOptions node can contain framework or frameworks (refer https://github.com/dotnet/sdk/blob/main/documentation/specs/runtime-configuration-file.md#runtimeoptions-section-runtimeconfigjson).
195
+ var frameworkNode = runtimeOptions [ "framework" ] ;
196
+ var frameworksNode = runtimeOptions [ "frameworks" ] ;
197
+
198
+ if ( IsAspNetFramework ( frameworkNode ) )
199
+ {
200
+ return file ;
201
+ }
202
+
203
+ if ( frameworksNode != null && frameworksNode . Count > 0 )
204
+ {
205
+ foreach ( var framework in frameworksNode )
206
+ {
207
+ var tempNode = framework as JsonData ;
208
+ if ( IsAspNetFramework ( tempNode ) )
209
+ {
210
+ return file ;
211
+ }
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ return Directory . GetFiles ( publishLocation , "*.runtimeconfig.json" ) . FirstOrDefault ( ) ;
218
+ }
219
+
220
+ private static bool IsAspNetFramework ( JsonData frameworkNode )
221
+ {
222
+ if ( frameworkNode != null )
223
+ {
224
+ var name = frameworkNode [ "name" ] ;
225
+
226
+ if ( name != null )
227
+ {
228
+ string frameworkName = ( string ) name ;
229
+ return ! string . IsNullOrEmpty ( frameworkName ) && frameworkName . StartsWith ( "Microsoft.AspNetCore" ) ;
230
+ }
231
+ }
232
+
233
+ return false ;
234
+ }
178
235
}
179
236
}
0 commit comments