build.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. bash --version 2>&1 | head -n 1
  3. set -eo pipefail
  4. SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
  5. ###########################################################################
  6. # CONFIGURATION
  7. ###########################################################################
  8. BUILD_PROJECT_FILE="$SCRIPT_DIR/build/_build.csproj"
  9. TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp"
  10. DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json"
  11. DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh"
  12. DOTNET_CHANNEL="Current"
  13. export DOTNET_CLI_TELEMETRY_OPTOUT=1
  14. export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
  15. export DOTNET_MULTILEVEL_LOOKUP=0
  16. ###########################################################################
  17. # EXECUTION
  18. ###########################################################################
  19. function FirstJsonValue {
  20. perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}"
  21. }
  22. # If dotnet CLI is installed globally and it matches requested version, use for execution
  23. if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then
  24. export DOTNET_EXE="$(command -v dotnet)"
  25. else
  26. # Download install script
  27. DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh"
  28. mkdir -p "$TEMP_DIRECTORY"
  29. curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL"
  30. chmod +x "$DOTNET_INSTALL_FILE"
  31. # If global.json exists, load expected version
  32. if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then
  33. DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")")
  34. if [[ "$DOTNET_VERSION" == "" ]]; then
  35. unset DOTNET_VERSION
  36. fi
  37. fi
  38. # Install by channel or version
  39. DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix"
  40. if [[ -z ${DOTNET_VERSION+x} ]]; then
  41. "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path
  42. else
  43. "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path
  44. fi
  45. export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet"
  46. fi
  47. echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)"
  48. "$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet
  49. "$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"