in src/startupscriptgenerator/src/dotnetcore/scriptgenerator.go [72:170]
func (gen *DotnetCoreStartupScriptGenerator) GenerateEntrypointScript(scriptBuilder *strings.Builder) string {
logger := common.GetLogger("dotnetcore.scriptgenerator.GenerateEntrypointScript")
defer logger.Shutdown()
logger.LogInformation("Generating script for published output.")
common.SetupPreRunScript(scriptBuilder, gen.AppPath, gen.Configuration.PreRunCommand)
// Expose the port so that a custom command can use it if needed
common.SetEnvironmentVariableInScript(scriptBuilder, "PORT", gen.BindPort, DefaultBindPort)
scriptBuilder.WriteString("export ASPNETCORE_URLS=http://*:$PORT\n\n")
appPath := gen.AppPath
if gen.RunFromPath != "" {
appPath = gen.RunFromPath
}
dotnetBinary := "/usr/share/dotnet/dotnet"
if gen.Configuration.EnableDynamicInstall && !common.PathExists(dotnetBinary) {
scriptBuilder.WriteString(fmt.Sprintf("oryx setupEnv -appPath %s\n", appPath))
}
logger.LogInformation("Looking for App-Insights configuration and Enable codeless attach if needed")
if gen.shouldApplicationInsightsBeConfigured() {
// We are going to set env variables in the startup logic
// for appinsights attach experience only if dotnetcore 6 or newer
fmt.Printf("Environment Variables for Application Insight's Codeless Configuration exists.. \n")
fmt.Printf("Setting up Environment Variables for Application Insights for codeless config.. \n")
scriptBuilder.WriteString("echo Setting up Application Insights for codeless config.. \n")
scriptBuilder.WriteString("export ASPNETCORE_HOSTINGSTARTUPASSEMBLIES="+consts.UserNetcoreHostingstartupAssemblies+"\n")
scriptBuilder.WriteString("export DOTNET_STARTUP_HOOKS="+consts.UserDotnetStartupHooks+"\n")
fmt.Printf("Setting up Environment Variables for Application Insights is done.. \n")
}
runDefaultApp := false
if gen.UserStartupCommand != "" {
// NOTE: do NOT try printing the command itself
scriptBuilder.WriteString("echo Running user provided startup command...\n")
scriptBuilder.WriteString("cd \"" + appPath + "\"\n")
scriptBuilder.WriteString(gen.UserStartupCommand)
} else {
if gen.Manifest.StartupDllFileName != "" {
scriptBuilder.WriteString("echo Found startup DLL name from manifest file\n")
startupCommand := "dotnet \"" + gen.Manifest.StartupDllFileName + "\""
scriptBuilder.WriteString("echo 'Running the command: " + startupCommand + "'\n")
scriptBuilder.WriteString("cd \"" + appPath + "\"\n")
scriptBuilder.WriteString(startupCommand + "\n")
} else {
scriptBuilder.WriteString("echo Trying to find the startup DLL name...\n")
runtimeConfigFiles := gen.getRuntimeConfigJsonFiles()
if len(runtimeConfigFiles) == 0 {
fmt.Printf(
"WARNING: Unable to find the startup DLL name. Could not find any files with extension '%s'\n",
RuntimeConfigJsonExtension)
runDefaultApp = true
} else if len(runtimeConfigFiles) > 1 {
fmt.Printf(
"WARNING: Expected to find only one file with extension '%s' but found %d\n",
RuntimeConfigJsonExtension,
len(runtimeConfigFiles))
fmt.Printf("WARNING: Found files: '%s'\n", strings.Join(runtimeConfigFiles, ", "))
fmt.Println("WARNING: To fix this issue you can set the startup command to point to a particular startup file")
fmt.Println(" For example: 'dotnet myapp.dll'")
runDefaultApp = true
} else {
runtimeConfigFile := runtimeConfigFiles[0]
startupDllName := strings.TrimSuffix(runtimeConfigFile, RuntimeConfigJsonExtension) + ".dll"
startupDllFullPath := filepath.Join(appPath, startupDllName)
if common.FileExists(startupDllFullPath) {
startupCommand := "dotnet \"" + startupDllName + "\""
scriptBuilder.WriteString("echo Found the startup D name: " + startupDllName + "\n")
scriptBuilder.WriteString("echo 'Running the command: " + startupCommand + "'\n")
scriptBuilder.WriteString("cd \"" + appPath + "\"\n")
scriptBuilder.WriteString(startupCommand + "\n")
} else {
fmt.Printf(
"WARNING: Unable to figure out startup D name. Found file '%s', but could not find startup file '%s' on disk.\n",
runtimeConfigFile,
startupDllFullPath)
runDefaultApp = true
}
}
}
}
if runDefaultApp && gen.DefaultAppFilePath != "" {
defaultAppFileDir := filepath.Dir(gen.DefaultAppFilePath)
startupCommand := "dotnet \"" + gen.DefaultAppFilePath + "\""
scriptBuilder.WriteString("echo 'Running the default app using command: " + startupCommand + "'\n")
scriptBuilder.WriteString("cd \"" + defaultAppFileDir + "\"\n")
scriptBuilder.WriteString(startupCommand + "\n")
}
var runScript = scriptBuilder.String()
return runScript
}