88
99set -eo pipefail
1010
11- # .NET version for agent build.
12- NET_VERSIONS="
13- net6.0-sdk=6.0.424
14- net6.0-runtime=6.0.32
15-
16- net8.0-sdk=8.0.401
17- net8.0-runtime=8.0.8"
18-
1911ALL_ARGS=(" $@ " )
2012DEV_CMD=$1
2113TARGET_FRAMEWORK=$2
@@ -48,28 +40,73 @@ if [[ $TARGET_FRAMEWORK == "" ]]; then
4840 TARGET_FRAMEWORK=$DEFAULT_TARGET_FRAMEWORK
4941fi
5042
51- function get_net_version ()
52- {
53- echo " $NET_VERSIONS " | grep -o " $1 =[^ ]*" | cut -d ' =' -f2
43+ function get_net_version() {
44+ local dotnet_versions="
45+ net6.0-sdk=6.0.424
46+ net6.0-runtime=6.0.32
47+
48+ net8.0-sdk=8.0.401
49+ net8.0-runtime=8.0.8
50+ "
51+
52+ echo " $dotnet_versions " | grep -o " $1 =[^ ]*" | cut -d ' =' -f2
5453}
5554
56- DOTNETSDK_VERSION =$( get_net_version " ${TARGET_FRAMEWORK} -sdk" )
57- DOTNETRUNTIME_VERSION =$( get_net_version " ${TARGET_FRAMEWORK} -runtime" )
55+ DOTNET_SDK_VERSION =$( get_net_version " net8.0 -sdk" )
56+ DOTNET_RUNTIME_VERSION =$( get_net_version " ${TARGET_FRAMEWORK} -runtime" )
5857
59- if [[ ($DOTNETSDK_VERSION == " " ) || ($DOTNETRUNTIME_VERSION == " " ) ]]; then
58+ if [[ ($DOTNET_SDK_VERSION == " " ) || ($DOTNET_RUNTIME_VERSION == " " ) ]]; then
6059 failed " Incorrect target framework is specified"
6160fi
6261
63- DOTNETSDK_ROOT=" ${REPO_ROOT} /_dotnetsdk"
64- DOTNETSDK_INSTALLDIR=" $DOTNETSDK_ROOT /$DOTNETSDK_VERSION "
62+ DOTNET_DIR=" ${REPO_ROOT} /_dotnetsdk"
6563
6664BUILD_CONFIG=" Debug"
6765if [[ " $DEV_CONFIG " == " Release" ]]; then
6866 BUILD_CONFIG=" Release"
6967fi
7068
71- function detect_platform_and_runtime_id ()
72- {
69+ restore_dotnet_install_script () {
70+ # run dotnet-install.ps1 on windows, dotnet-install.sh on linux
71+ if [[ " ${CURRENT_PLATFORM} " == " windows" ]]; then
72+ ext=" ps1"
73+ else
74+ ext=" sh"
75+ fi
76+
77+ DOTNET_INSTALL_SCRIPT_NAME=" dotnet-install.${ext} "
78+ DOTNET_INSTALL_SCRIPT_PATH=" ./Misc/${DOTNET_INSTALL_SCRIPT_NAME} "
79+
80+ if [[ ! -e " ${DOTNET_INSTALL_SCRIPT_PATH} " ]]; then
81+ curl -sSL " https://dot.net/v1/${DOTNET_INSTALL_SCRIPT_NAME} " -o " ${DOTNET_INSTALL_SCRIPT_PATH} "
82+ fi
83+ }
84+
85+ function restore_sdk_and_runtime() {
86+ heading " Install .NET SDK ${DOTNET_SDK_VERSION} and Runtime ${DOTNET_RUNTIME_VERSION} "
87+
88+ if [[ " ${CURRENT_PLATFORM} " == " windows" ]]; then
89+ echo " Convert ${DOTNET_DIR} to Windows style path"
90+ local dotnet_windows_dir=${DOTNET_DIR: 1}
91+ dotnet_windows_dir=${dotnet_windows_dir: 0: 1} :${dotnet_windows_dir: 1}
92+ local architecture
93+ architecture=$( echo " $RUNTIME_ID " | cut -d " -" -f2)
94+
95+ printf " \nInstalling SDK...\n"
96+ powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command " & \" ${DOTNET_INSTALL_SCRIPT_PATH} \" -Version ${DOTNET_SDK_VERSION} -InstallDir \" ${dotnet_windows_dir} \" -Architecture ${architecture} -NoPath; exit \$ LastExitCode;" || checkRC " ${DOTNET_INSTALL_SCRIPT_NAME} (SDK)"
97+
98+ printf " \nInstalling Runtime...\n"
99+ powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command " & \" ${DOTNET_INSTALL_SCRIPT_PATH} \" -Runtime dotnet -Version ${DOTNET_RUNTIME_VERSION} -InstallDir \" ${dotnet_windows_dir} \" -Architecture ${architecture} -SkipNonVersionedFiles -NoPath; exit \$ LastExitCode;" || checkRC " ${DOTNET_INSTALL_SCRIPT_NAME} (Runtime)"
100+ else
101+ printf " \nInstalling SDK...\n"
102+ bash " ${DOTNET_INSTALL_SCRIPT_PATH} " --version " ${DOTNET_SDK_VERSION} " --install-dir " ${DOTNET_DIR} " --no-path || checkRC " ${DOTNET_INSTALL_SCRIPT_NAME} (SDK)"
103+
104+ printf " \nInstalling Runtime...\n"
105+ bash " ${DOTNET_INSTALL_SCRIPT_PATH} " --runtime dotnet --version " ${DOTNET_RUNTIME_VERSION} " --install-dir " ${DOTNET_DIR} " --skip-non-versioned-files --no-path || checkRC " ${DOTNET_INSTALL_SCRIPT_NAME} (Runtime)"
106+ fi
107+ }
108+
109+ function detect_platform_and_runtime_id() {
73110 heading " Platform / RID detection"
74111
75112 CURRENT_PLATFORM=" windows"
@@ -84,11 +121,11 @@ function detect_platform_and_runtime_id ()
84121 fi
85122 elif [[ " $CURRENT_PLATFORM " == ' linux' ]]; then
86123 DETECTED_RUNTIME_ID=" linux-x64"
87- if command -v uname > /dev/null; then
124+ if command -v uname > /dev/null; then
88125 local CPU_NAME=$( uname -m)
89126 case $CPU_NAME in
90- armv7l) DETECTED_RUNTIME_ID=" linux-arm" ;;
91- aarch64) DETECTED_RUNTIME_ID=" linux-arm64" ;;
127+ armv7l) DETECTED_RUNTIME_ID=" linux-arm" ;;
128+ aarch64) DETECTED_RUNTIME_ID=" linux-arm64" ;;
92129 esac
93130 fi
94131
@@ -108,45 +145,43 @@ function detect_platform_and_runtime_id ()
108145 fi
109146 elif [[ " $CURRENT_PLATFORM " == ' darwin' ]]; then
110147 DETECTED_RUNTIME_ID=' osx-x64'
111- if command -v uname > /dev/null; then
148+ if command -v uname > /dev/null; then
112149 local CPU_NAME=$( uname -m)
113150 case $CPU_NAME in
114- arm64) DETECTED_RUNTIME_ID=" osx-arm64" ;;
151+ arm64) DETECTED_RUNTIME_ID=" osx-arm64" ;;
115152 esac
116153 fi
117154 fi
118155}
119156
120- function make_build () {
157+ function make_build() {
121158 TARGET=$1
122159
123160 echo " MSBuild target = ${TARGET} "
124161
125- if [[ " $ADO_ENABLE_LOGISSUE " == " true" ]]; then
162+ if [[ " $ADO_ENABLE_LOGISSUE " == " true" ]]; then
126163
127- dotnet msbuild -t:" ${TARGET} " -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:CodeAnalysis=" true" -p:NetTargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeVersion =" ${DOTNETRUNTIME_VERSION } " \
128- | sed -e " /\: warning /s/^/${DOTNET_WARNING_PREFIX} /;" \
129- | sed -e " /\: error /s/^/${DOTNET_ERROR_PREFIX} /;" \
130- || failed build
164+ dotnet msbuild -t:" ${TARGET} " -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:CodeAnalysis=" true" -p:TargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeFrameworkVersion =" ${DOTNET_RUNTIME_VERSION } " |
165+ sed -e " /\: warning /s/^/${DOTNET_WARNING_PREFIX} /;" |
166+ sed -e " /\: error /s/^/${DOTNET_ERROR_PREFIX} /;" ||
167+ failed build
131168 else
132- dotnet msbuild -t:" ${TARGET} " -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:CodeAnalysis=" true" -p:NetTargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeVersion =" ${DOTNETRUNTIME_VERSION } " \
133- || failed build
169+ dotnet msbuild -t:" ${TARGET} " -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:CodeAnalysis=" true" -p:TargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeFrameworkVersion =" ${DOTNET_RUNTIME_VERSION } " ||
170+ failed build
134171 fi
135172
136173 mkdir -p " ${LAYOUT_DIR} /bin/en-US"
137174
138- grep -v ' ^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > " ${LAYOUT_DIR} /bin/en-US/strings.json"
175+ grep -v ' ^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > " ${LAYOUT_DIR} /bin/en-US/strings.json"
139176}
140177
141- function cmd_build ()
142- {
178+ function cmd_build() {
143179 heading " Building"
144180
145181 make_build " Build"
146182}
147183
148- function cmd_layout ()
149- {
184+ function cmd_layout() {
150185 heading " Creating layout"
151186
152187 make_build " Layout"
@@ -163,8 +198,7 @@ function cmd_layout ()
163198 bash ./Misc/externals.sh $RUNTIME_ID || checkRC externals.sh
164199}
165200
166- function cmd_test_l0 ()
167- {
201+ function cmd_test_l0() {
168202 heading " Testing L0"
169203
170204 if [[ (" $CURRENT_PLATFORM " == " linux" ) || (" $CURRENT_PLATFORM " == " darwin" ) ]]; then
@@ -176,12 +210,12 @@ function cmd_test_l0 ()
176210 TestFilters=" $TestFilters &$DEV_TEST_FILTERS "
177211 fi
178212
179- dotnet msbuild -t:testl0 -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:TestFilters=" ${TestFilters} " -p:NetTargetFramework =" ${TARGET_FRAMEWORK} " " ${DEV_ARGS[@]} " || failed " failed tests"
213+ dotnet msbuild -t:testl0 -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:TestFilters=" ${TestFilters} " -p:TargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeFrameworkVersion= " ${DOTNET_RUNTIME_VERSION }" " ${DEV_ARGS[@]} " || failed " failed tests"
180214}
181215
182- function cmd_test_l1 ()
183- {
216+ function cmd_test_l1() {
184217 heading " Clean"
218+
185219 dotnet msbuild -t:cleanl1 -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " || failed build
186220
187221 heading " Setup externals folder for $RUNTIME_ID agent's layout"
@@ -198,18 +232,16 @@ function cmd_test_l1 ()
198232 TestFilters=" $TestFilters &$DEV_TEST_FILTERS "
199233 fi
200234
201- dotnet msbuild -t:testl1 -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:TestFilters=" ${TestFilters} " -p:NetTargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeVersion =" ${DOTNETRUNTIME_VERSION } " " ${DEV_ARGS[@]} " || failed " failed tests"
235+ dotnet msbuild -t:testl1 -p:PackageRuntime=" ${RUNTIME_ID} " -p:PackageType=" ${PACKAGE_TYPE} " -p:BUILDCONFIG=" ${BUILD_CONFIG} " -p:AgentVersion=" ${AGENT_VERSION} " -p:LayoutRoot=" ${LAYOUT_DIR} " -p:TestFilters=" ${TestFilters} " -p:TargetFramework =" ${TARGET_FRAMEWORK} " -p:RuntimeFrameworkVersion =" ${DOTNET_RUNTIME_VERSION } " " ${DEV_ARGS[@]} " || failed " failed tests"
202236}
203237
204- function cmd_test ()
205- {
238+ function cmd_test() {
206239 cmd_test_l0
207240
208241 cmd_test_l1
209242}
210243
211- function cmd_package ()
212- {
244+ function cmd_package() {
213245 if [ ! -d " ${LAYOUT_DIR} /bin" ]; then
214246 echo " You must build first. Expecting to find ${LAYOUT_DIR} /bin"
215247 fi
@@ -237,7 +269,7 @@ function cmd_package ()
237269 mkdir -p " $PACKAGE_DIR "
238270 rm -Rf " ${PACKAGE_DIR:? } " /*
239271
240- pushd " $PACKAGE_DIR " > /dev/null
272+ pushd " $PACKAGE_DIR " > /dev/null
241273
242274 if [[ (" $CURRENT_PLATFORM " == " linux" ) || (" $CURRENT_PLATFORM " == " darwin" ) ]]; then
243275 tar_name=" ${agent_pkg_name} .tar.gz"
@@ -252,16 +284,15 @@ function cmd_package ()
252284 powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command " Add-Type -Assembly \" System.IO.Compression.FileSystem\" ; [System.IO.Compression.ZipFile]::CreateFromDirectory(\" ${window_path} \" , \" ${zip_name} \" )"
253285 fi
254286
255- popd > /dev/null
287+ popd > /dev/null
256288}
257289
258- function cmd_hash ()
259- {
260- pushd " $PACKAGE_DIR " > /dev/null
290+ function cmd_hash() {
291+ pushd " $PACKAGE_DIR " > /dev/null
261292
262- files=` ls -1`
293+ files=$( ls -1)
263294
264- number_of_files=` wc -l <<< " $files" `
295+ number_of_files=$( wc -l <<< " $files" )
265296
266297 if [[ number_of_files -ne 1 ]]; then
267298 echo " Expecting to find exactly one file (agent package) in $PACKAGE_DIR "
@@ -272,13 +303,12 @@ function cmd_hash ()
272303
273304 rm -rf ../../_package_hash
274305 mkdir ../../_package_hash
275- openssl dgst -sha256 $agent_package_file >> " ../../_package_hash/$agent_package_file .sha256"
306+ openssl dgst -sha256 $agent_package_file >> " ../../_package_hash/$agent_package_file .sha256"
276307
277- popd > /dev/null
308+ popd > /dev/null
278309}
279310
280- function cmd_report ()
281- {
311+ function cmd_report() {
282312 heading " Generating Reports"
283313
284314 if [[ (" $CURRENT_PLATFORM " ! = " windows" ) ]]; then
@@ -302,11 +332,11 @@ function cmd_report ()
302332 echo " Converting to XML file $COVERAGE_XML_FILE "
303333
304334 # for some reason CodeCoverage.exe will only write the output file in the current directory
305- pushd $COVERAGE_REPORT_DIR > /dev/null
306- " ${HOME} /.nuget/packages/microsoft.codecoverage/16.4.0/build/netstandard1.0/CodeCoverage/CodeCoverage.exe" analyze " /output:coverage.xml" " $LATEST_COVERAGE_FILE "
307- popd > /dev/null
335+ pushd $COVERAGE_REPORT_DIR > /dev/null
336+ " ${HOME} /.nuget/packages/microsoft.codecoverage/16.4.0/build/netstandard1.0/CodeCoverage/CodeCoverage.exe" analyze " /output:coverage.xml" " $LATEST_COVERAGE_FILE "
337+ popd > /dev/null
308338
309- if ! command -v reportgenerator.exe > /dev/null; then
339+ if ! command -v reportgenerator.exe > /dev/null; then
310340 echo " reportgenerator not installed. Skipping generation of HTML reports"
311341 echo " To install: "
312342 echo " % dotnet tool install --global dotnet-reportgenerator-globaltool"
@@ -340,49 +370,12 @@ DOWNLOAD_DIR="${REPO_ROOT}/_downloads/${RUNTIME_ID}/netcore2x"
340370PACKAGE_DIR=" ${REPO_ROOT} /_package/${RUNTIME_ID} "
341371REPORT_DIR=" ${REPO_ROOT} /_reports/${RUNTIME_ID} "
342372
343- if [[ (! -d " ${DOTNETSDK_INSTALLDIR} " ) || (! -e " ${DOTNETSDK_INSTALLDIR} /.${DOTNETSDK_VERSION} " ) || (! -e " ${DOTNETSDK_INSTALLDIR} /dotnet" ) ]]; then
344-
345- # Download dotnet SDK to ../_dotnetsdk directory
346- heading " Install .NET SDK"
347-
348- # _dotnetsdk
349- # \1.0.x
350- # \dotnet
351- # \.1.0.x
352- echo " Download dotnetsdk into ${DOTNETSDK_INSTALLDIR} "
353- rm -Rf " ${DOTNETSDK_DIR} "
354-
355- # run dotnet-install.ps1 on windows, dotnet-install.sh on linux
356- if [[ " ${CURRENT_PLATFORM} " == " windows" ]]; then
357- ext=" ps1"
358- else
359- ext=" sh"
360- fi
361-
362- DOTNET_INSTALL_SCRIPT_NAME=" dotnet-install.${ext} "
363- DOTNET_INSTALL_SCRIPT_PATH=" ./Misc/${DOTNET_INSTALL_SCRIPT_NAME} "
364-
365- if [[ ! -e " ${DOTNET_INSTALL_SCRIPT_PATH} " ]]; then
366- curl -sSL " https://dot.net/v1/${DOTNET_INSTALL_SCRIPT_NAME} " -o " ${DOTNET_INSTALL_SCRIPT_PATH} "
367- fi
368-
369- if [[ " ${CURRENT_PLATFORM} " == " windows" ]]; then
370- echo " Convert ${DOTNETSDK_INSTALLDIR} to Windows style path"
371- sdkinstallwindow_path=${DOTNETSDK_INSTALLDIR: 1}
372- sdkinstallwindow_path=${sdkinstallwindow_path: 0: 1} :${sdkinstallwindow_path: 1}
373- architecture=$( echo $RUNTIME_ID | cut -d " -" -f2)
374- powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command " & \" ${DOTNET_INSTALL_SCRIPT_PATH} \" -Version ${DOTNETSDK_VERSION} -InstallDir \" ${sdkinstallwindow_path} \" -Architecture ${architecture} -NoPath; exit \$ LastExitCode;" || checkRC " ${DOTNET_INSTALL_SCRIPT_NAME} "
375- else
376- bash " ${DOTNET_INSTALL_SCRIPT_PATH} " --version ${DOTNETSDK_VERSION} --install-dir " ${DOTNETSDK_INSTALLDIR} " --no-path || checkRC " ${DOTNET_INSTALL_SCRIPT_NAME} "
377- fi
378-
379- echo " ${DOTNETSDK_VERSION} " > " ${DOTNETSDK_INSTALLDIR} /.${DOTNETSDK_VERSION} "
380- fi
373+ restore_dotnet_install_script
374+ restore_sdk_and_runtime
381375
382376heading " .NET SDK to path"
383-
384- echo " Adding .NET to PATH (${DOTNETSDK_INSTALLDIR} )"
385- export PATH=${DOTNETSDK_INSTALLDIR} :$PATH
377+ echo " Adding .NET SDK to PATH (${DOTNET_DIR} )"
378+ export PATH=${DOTNET_DIR} :$PATH
386379echo " Path = $PATH "
387380echo " .NET Version = $( dotnet --version) "
388381
@@ -407,21 +400,21 @@ if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then
407400fi
408401
409402case $DEV_CMD in
410- " build" ) cmd_build;;
411- " b" ) cmd_build;;
412- " test" ) cmd_test;;
413- " t" ) cmd_test;;
414- " testl0" ) cmd_test_l0;;
415- " l0" ) cmd_test_l0;;
416- " testl1" ) cmd_test_l1;;
417- " l1" ) cmd_test_l1;;
418- " layout" ) cmd_layout;;
419- " l" ) cmd_layout;;
420- " package" ) cmd_package;;
421- " p" ) cmd_package;;
422- " hash" ) cmd_hash;;
423- " report" ) cmd_report;;
424- * ) echo " Invalid command. Use (l)ayout, (b)uild, (t)est, test(l0), test(l1), or (p)ackage." ;;
403+ " build" ) cmd_build ;;
404+ " b" ) cmd_build ;;
405+ " test" ) cmd_test ;;
406+ " t" ) cmd_test ;;
407+ " testl0" ) cmd_test_l0 ;;
408+ " l0" ) cmd_test_l0 ;;
409+ " testl1" ) cmd_test_l1 ;;
410+ " l1" ) cmd_test_l1 ;;
411+ " layout" ) cmd_layout ;;
412+ " l" ) cmd_layout ;;
413+ " package" ) cmd_package ;;
414+ " p" ) cmd_package ;;
415+ " hash" ) cmd_hash ;;
416+ " report" ) cmd_report ;;
417+ * ) echo " Invalid command. Use (l)ayout, (b)uild, (t)est, test(l0), test(l1), or (p)ackage." ;;
425418esac
426419
427420popd
0 commit comments