Skip to content

Commit

Permalink
Fix .NET Core startup script startup command (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
kichalla authored Jun 10, 2019
1 parent c2ee5d8 commit 61c21ec
Show file tree
Hide file tree
Showing 11 changed files with 613 additions and 225 deletions.
94 changes: 60 additions & 34 deletions src/startupscriptgenerator/dotnetcore/scriptgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (gen *DotnetCoreStartupScriptGenerator) GenerateEntrypointScript(scriptBuil
defaultAppFileDir := filepath.Dir(gen.DefaultAppFilePath)

scriptBuilder.WriteString("readonly appPath=\"" + gen.RunFromPath + "\"\n")
scriptBuilder.WriteString("userStartUpCommand=\"" + gen.UserStartupCommand + "\"\n")
scriptBuilder.WriteString("userStartUpCommand=(" + gen.UserStartupCommand + ")\n")
scriptBuilder.WriteString("startUpCommand=\"\"\n")
scriptBuilder.WriteString("readonly defaultAppFileDir=\"" + defaultAppFileDir + "\"\n")
scriptBuilder.WriteString("readonly defaultAppFilePath=\"" + gen.DefaultAppFilePath + "\"\n")
Expand All @@ -53,43 +53,57 @@ isLinuxExecutable() {
}
cd "$appPath"
if [ ! -z "$userStartUpCommand" ]; then
len=${#userStartUpCommand[@]}
if [ "$len" -eq "1" ]; then
len=${#userStartUpCommand[@]}
startupCommandString="${userStartUpCommand[@]}"
if [ $len -ne 0 ]; then
echo "Trying to use provided startup command: $startupCommandString"
isValid=true
if [ $len -eq 1 ]; then
file="${userStartUpCommand[0]}"
if [ -f "$file" ]; then
# The startup command could be for example: 'todoApp' or './todoApp'
# So just extract the 'todoApp' part and prefix it with './' to be './todoApp'
startUpCommand="./${file##*/}"
else
echo "Could not find the startup file '$file' on disk."
if [ ! -f "$file" ]; then
isValid=false
echo "WARNING: Could not find the startup file '$file' on disk."
fi
elif [ "$len" -eq "2" ] && [ "${userStartUpCommand[0]}" == "dotnet" ]; then
if [ -f "${userStartUpCommand[1]}" ]; then
startUpCommand="$userStartUpCommand"
else
echo "Could not find the file '${userStartUpCommand[1]}' on disk."
elif [ $len -eq 2 ] && [ "${userStartUpCommand[0]}" == "dotnet" ]; then
if [ ! -f "${userStartUpCommand[1]}" ]; then
isValid=false
echo "WARNING: Could not find the file '${userStartUpCommand[1]}' on disk."
fi
else
startUpCommand="$userStartUpCommand"
fi
fi
if [ -z "$startUpCommand" ]; then
echo Finding the startup file name...
for file in *; do
if [ -f "$file" ]; then
if [ $isValid = true ]; then
startUpCommand="$startupCommandString"
fi
else
echo "Startup command was not provided, finding the startup file name..."
runtimeConfigJsonFiles=()
for file in *; do
if [ -f "$file" ]; then
case $file in
*.runtimeconfig.json)
startupDllFileNamePrefix=${file%%.runtimeconfig.json}
startupExecutableFileName="$startupDllFileNamePrefix"
startupDllFileName="$startupDllFileNamePrefix.dll"
break
;;
*.runtimeconfig.json)
runtimeConfigJsonFiles+=("$file")
;;
esac
fi
done
fileCount=${#runtimeConfigJsonFiles[@]}
if [ $fileCount -eq 1 ]; then
file=${runtimeConfigJsonFiles[0]}
startupDllFileNamePrefix=${file%%.runtimeconfig.json}
startupExecutableFileName="$startupDllFileNamePrefix"
startupDllFileName="$startupDllFileNamePrefix.dll"
else
echo "WARNING: Unable to find the startup dll file name."
echo "WARNING: Expected to find only one file with extension 'runtimeconfig.json' but found $fileCount"
if [ $fileCount -gt 1 ]; then
echo "WARNING: Found files: ${runtimeConfigJsonFiles[@]}"
echo "WARNING: To fix this issue you can set the startup command to point to a particular startup file"
echo " For example: 'dotnet myapp.dll'"
fi
fi
if [ -f "$startupExecutableFileName" ]; then
# Starting ASP.NET Core 3.0, an executable is created based on the platform where it is published from,
# so for example, if a user does a publish (not self-contained) on Mac, there would be files like 'todoApp'
Expand All @@ -105,22 +119,34 @@ if [ -z "$startUpCommand" ]; then
fi
fi
if [ -z "$startUpCommand" ] && [ -f "$startupDllFileName" ]; then
if [ -z "$startUpCommand" ] && [ ! -z "$startupDllFileName" ]; then
if [ -f "$startupDllFileName" ]; then
echo "Found the startup file '$startupDllFileName'"
startUpCommand="dotnet '$startupDllFileName'"
else
echo "Cound not find the startup dll file '$startupDllFileName'"
fi
fi
fi
if [ -z "$startUpCommand" ]; then
if [ -f "$defaultAppFilePath" ]; then
cd "$defaultAppFileDir"
startUpCommand="dotnet '$defaultAppFilePath'"
echo "Trying to run the default app instead..."
if [ ! -z "$defaultAppFilePath" ]; then
if [ -f "$defaultAppFilePath" ]; then
cd "$defaultAppFileDir"
startUpCommand="dotnet '$defaultAppFilePath'"
else
echo "Could not find the default app file '$defaultAppFilePath'"
fi
else
echo Unable to start the application.
exit 1
echo "Default app was not provided. Unable to start the application."
fi
fi
if [ -z "$startUpCommand" ]; then
exit 1
fi
echo "Running the command '$startUpCommand'..."
eval "$startUpCommand"
`
Expand Down
Loading

0 comments on commit 61c21ec

Please sign in to comment.