-
Notifications
You must be signed in to change notification settings - Fork 13
/
dotnet-directory
executable file
·94 lines (83 loc) · 1.98 KB
/
dotnet-directory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
# This is a script called by multiple tests to find the runtime
# directory of the current platform.
set -euo pipefail
print_err()
{
echo "err: $@" 1>&2;
}
print_usage() {
echo "usage: $0 [--root (default) | --sdk | --framework <runtime version> | --help ]" 1>&2
echo "" 1>&2
echo "Shows a .NET directory." 1>&2
}
if [ "${1:-}" == "--help" ]; then
print_usage
exit 0
fi
dotnet_command_path=$(command -v dotnet || true)
if [ -z "$dotnet_command_path" ]; then
print_err "'dotnet' command not found."
exit 1
fi
dotnet_dir=$(dirname "$(realpath "$dotnet_command_path")")
print_root() {
if [ ! -d "$dotnet_dir" ]; then
print_err "dotnet root directory not found."
exit 1
fi
echo "${dotnet_dir}"
exit 0
}
print_sdk() {
local sdk_version="$(dotnet --version)"
local sdk_dir="${dotnet_dir}/sdk/${sdk_version}"
if [ ! -d "$sdk_dir" ]; then
print_err "sdk directory for $sdk_version not found."
exit 1
fi
echo "${sdk_dir}"
exit 0
}
print_framework() {
if [[ $# -lt 2 ]]; then
print_err "Missing <version> argument."
exit 1
fi
local dir_name="$1"
local version="$2"
declare -a versions
IFS='.-' read -ra versions <<< "${version}"
framework_dirs=( "${dotnet_dir}/shared/$dir_name/${versions[0]}.${versions[1]:-}"* )
framework_dir="${framework_dirs[0]}"
if [ ! -d "$framework_dir" ]; then
print_err "framework directory for $version not found."
exit 1
fi
echo "${framework_dir}"
exit 0
}
if [[ $# -eq 0 ]]; then
command="--root"
else
command="$1"
shift
fi
case "$command" in
--root)
print_root "$@"
;;
--framework)
print_framework "Microsoft.NETCore.App" "$@"
;;
--aspnet)
print_framework "Microsoft.AspNetCore.App" "$@"
;;
--sdk)
print_sdk "$@"
;;
*)
print_err "unknown argument: $1."
print_usage
exit 1
esac