Skip to content

Commit

Permalink
Fix intellisense: Replaced custom target framework prop to built-in w…
Browse files Browse the repository at this point in the history
…ith predefined value (#5000)

* Replace custom target framework prop to built-in with predefined value
  • Loading branch information
KonstantinTyukalov authored Oct 17, 2024
1 parent a54d86b commit 42229c7
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 125 deletions.
3 changes: 1 addition & 2 deletions src/Common.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>$(NetTargetFramework)</TargetFramework>
<RuntimeFrameworkVersion>$(RuntimeVersion)</RuntimeFrameworkVersion>
<TargetFrameworks>net6.0;net8.0</TargetFrameworks>
<RuntimeIdentifier Condition="'$(BuildingInsideVisualStudio)' != 'true'">$(PackageRuntime)</RuntimeIdentifier>
<SelfContained>true</SelfContained>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
Expand Down
227 changes: 110 additions & 117 deletions src/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

set -eo pipefail

# .NET version for agent build.
NET_VERSIONS="
net6.0-sdk=6.0.424
net6.0-runtime=6.0.32
net8.0-sdk=8.0.401
net8.0-runtime=8.0.8"

ALL_ARGS=("$@")
DEV_CMD=$1
TARGET_FRAMEWORK=$2
Expand Down Expand Up @@ -48,28 +40,73 @@ if [[ $TARGET_FRAMEWORK == "" ]]; then
TARGET_FRAMEWORK=$DEFAULT_TARGET_FRAMEWORK
fi

function get_net_version ()
{
echo "$NET_VERSIONS" | grep -o "$1=[^ ]*" | cut -d '=' -f2
function get_net_version() {
local dotnet_versions="
net6.0-sdk=6.0.424
net6.0-runtime=6.0.32
net8.0-sdk=8.0.401
net8.0-runtime=8.0.8
"

echo "$dotnet_versions" | grep -o "$1=[^ ]*" | cut -d '=' -f2
}

DOTNETSDK_VERSION=$(get_net_version "${TARGET_FRAMEWORK}-sdk")
DOTNETRUNTIME_VERSION=$(get_net_version "${TARGET_FRAMEWORK}-runtime")
DOTNET_SDK_VERSION=$(get_net_version "net8.0-sdk")
DOTNET_RUNTIME_VERSION=$(get_net_version "${TARGET_FRAMEWORK}-runtime")

if [[ ($DOTNETSDK_VERSION == "") || ($DOTNETRUNTIME_VERSION == "") ]]; then
if [[ ($DOTNET_SDK_VERSION == "") || ($DOTNET_RUNTIME_VERSION == "") ]]; then
failed "Incorrect target framework is specified"
fi

DOTNETSDK_ROOT="${REPO_ROOT}/_dotnetsdk"
DOTNETSDK_INSTALLDIR="$DOTNETSDK_ROOT/$DOTNETSDK_VERSION"
DOTNET_DIR="${REPO_ROOT}/_dotnetsdk"

BUILD_CONFIG="Debug"
if [[ "$DEV_CONFIG" == "Release" ]]; then
BUILD_CONFIG="Release"
fi

function detect_platform_and_runtime_id ()
{
restore_dotnet_install_script() {
# run dotnet-install.ps1 on windows, dotnet-install.sh on linux
if [[ "${CURRENT_PLATFORM}" == "windows" ]]; then
ext="ps1"
else
ext="sh"
fi

DOTNET_INSTALL_SCRIPT_NAME="dotnet-install.${ext}"
DOTNET_INSTALL_SCRIPT_PATH="./Misc/${DOTNET_INSTALL_SCRIPT_NAME}"

if [[ ! -e "${DOTNET_INSTALL_SCRIPT_PATH}" ]]; then
curl -sSL "https://dot.net/v1/${DOTNET_INSTALL_SCRIPT_NAME}" -o "${DOTNET_INSTALL_SCRIPT_PATH}"
fi
}

function restore_sdk_and_runtime() {
heading "Install .NET SDK ${DOTNET_SDK_VERSION} and Runtime ${DOTNET_RUNTIME_VERSION}"

if [[ "${CURRENT_PLATFORM}" == "windows" ]]; then
echo "Convert ${DOTNET_DIR} to Windows style path"
local dotnet_windows_dir=${DOTNET_DIR:1}
dotnet_windows_dir=${dotnet_windows_dir:0:1}:${dotnet_windows_dir:1}
local architecture
architecture=$(echo "$RUNTIME_ID" | cut -d "-" -f2)

printf "\nInstalling SDK...\n"
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)"

printf "\nInstalling Runtime...\n"
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)"
else
printf "\nInstalling SDK...\n"
bash "${DOTNET_INSTALL_SCRIPT_PATH}" --version "${DOTNET_SDK_VERSION}" --install-dir "${DOTNET_DIR}" --no-path || checkRC "${DOTNET_INSTALL_SCRIPT_NAME} (SDK)"

printf "\nInstalling Runtime...\n"
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)"
fi
}

function detect_platform_and_runtime_id() {
heading "Platform / RID detection"

CURRENT_PLATFORM="windows"
Expand All @@ -84,11 +121,11 @@ function detect_platform_and_runtime_id ()
fi
elif [[ "$CURRENT_PLATFORM" == 'linux' ]]; then
DETECTED_RUNTIME_ID="linux-x64"
if command -v uname > /dev/null; then
if command -v uname >/dev/null; then
local CPU_NAME=$(uname -m)
case $CPU_NAME in
armv7l) DETECTED_RUNTIME_ID="linux-arm";;
aarch64) DETECTED_RUNTIME_ID="linux-arm64";;
armv7l) DETECTED_RUNTIME_ID="linux-arm" ;;
aarch64) DETECTED_RUNTIME_ID="linux-arm64" ;;
esac
fi

Expand All @@ -108,45 +145,43 @@ function detect_platform_and_runtime_id ()
fi
elif [[ "$CURRENT_PLATFORM" == 'darwin' ]]; then
DETECTED_RUNTIME_ID='osx-x64'
if command -v uname > /dev/null; then
if command -v uname >/dev/null; then
local CPU_NAME=$(uname -m)
case $CPU_NAME in
arm64) DETECTED_RUNTIME_ID="osx-arm64";;
arm64) DETECTED_RUNTIME_ID="osx-arm64" ;;
esac
fi
fi
}

function make_build (){
function make_build() {
TARGET=$1

echo "MSBuild target = ${TARGET}"

if [[ "$ADO_ENABLE_LOGISSUE" == "true" ]]; then
if [[ "$ADO_ENABLE_LOGISSUE" == "true" ]]; then

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}" \
| sed -e "/\: warning /s/^/${DOTNET_WARNING_PREFIX} /;" \
| sed -e "/\: error /s/^/${DOTNET_ERROR_PREFIX} /;" \
|| failed build
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}" |
sed -e "/\: warning /s/^/${DOTNET_WARNING_PREFIX} /;" |
sed -e "/\: error /s/^/${DOTNET_ERROR_PREFIX} /;" ||
failed build
else
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}" \
|| failed build
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}" ||
failed build
fi

mkdir -p "${LAYOUT_DIR}/bin/en-US"

grep -v '^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json > "${LAYOUT_DIR}/bin/en-US/strings.json"
grep -v '^ *"CLI-WIDTH-' ./Misc/layoutbin/en-US/strings.json >"${LAYOUT_DIR}/bin/en-US/strings.json"
}

function cmd_build ()
{
function cmd_build() {
heading "Building"

make_build "Build"
}

function cmd_layout ()
{
function cmd_layout() {
heading "Creating layout"

make_build "Layout"
Expand All @@ -163,8 +198,7 @@ function cmd_layout ()
bash ./Misc/externals.sh $RUNTIME_ID || checkRC externals.sh
}

function cmd_test_l0 ()
{
function cmd_test_l0() {
heading "Testing L0"

if [[ ("$CURRENT_PLATFORM" == "linux") || ("$CURRENT_PLATFORM" == "darwin") ]]; then
Expand All @@ -176,12 +210,12 @@ function cmd_test_l0 ()
TestFilters="$TestFilters&$DEV_TEST_FILTERS"
fi

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"
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"
}

function cmd_test_l1 ()
{
function cmd_test_l1() {
heading "Clean"

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

heading "Setup externals folder for $RUNTIME_ID agent's layout"
Expand All @@ -198,18 +232,16 @@ function cmd_test_l1 ()
TestFilters="$TestFilters&$DEV_TEST_FILTERS"
fi

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"
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"
}

function cmd_test ()
{
function cmd_test() {
cmd_test_l0

cmd_test_l1
}

function cmd_package ()
{
function cmd_package() {
if [ ! -d "${LAYOUT_DIR}/bin" ]; then
echo "You must build first. Expecting to find ${LAYOUT_DIR}/bin"
fi
Expand Down Expand Up @@ -237,7 +269,7 @@ function cmd_package ()
mkdir -p "$PACKAGE_DIR"
rm -Rf "${PACKAGE_DIR:?}"/*

pushd "$PACKAGE_DIR" > /dev/null
pushd "$PACKAGE_DIR" >/dev/null

if [[ ("$CURRENT_PLATFORM" == "linux") || ("$CURRENT_PLATFORM" == "darwin") ]]; then
tar_name="${agent_pkg_name}.tar.gz"
Expand All @@ -252,16 +284,15 @@ function cmd_package ()
powershell -NoLogo -Sta -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command "Add-Type -Assembly \"System.IO.Compression.FileSystem\"; [System.IO.Compression.ZipFile]::CreateFromDirectory(\"${window_path}\", \"${zip_name}\")"
fi

popd > /dev/null
popd >/dev/null
}

function cmd_hash ()
{
pushd "$PACKAGE_DIR" > /dev/null
function cmd_hash() {
pushd "$PACKAGE_DIR" >/dev/null

files=`ls -1`
files=$(ls -1)

number_of_files=`wc -l <<< "$files"`
number_of_files=$(wc -l <<<"$files")

if [[ number_of_files -ne 1 ]]; then
echo "Expecting to find exactly one file (agent package) in $PACKAGE_DIR"
Expand All @@ -272,13 +303,12 @@ function cmd_hash ()

rm -rf ../../_package_hash
mkdir ../../_package_hash
openssl dgst -sha256 $agent_package_file >> "../../_package_hash/$agent_package_file.sha256"
openssl dgst -sha256 $agent_package_file >>"../../_package_hash/$agent_package_file.sha256"

popd > /dev/null
popd >/dev/null
}

function cmd_report ()
{
function cmd_report() {
heading "Generating Reports"

if [[ ("$CURRENT_PLATFORM" != "windows") ]]; then
Expand All @@ -302,11 +332,11 @@ function cmd_report ()
echo "Converting to XML file $COVERAGE_XML_FILE"

# for some reason CodeCoverage.exe will only write the output file in the current directory
pushd $COVERAGE_REPORT_DIR > /dev/null
"${HOME}/.nuget/packages/microsoft.codecoverage/16.4.0/build/netstandard1.0/CodeCoverage/CodeCoverage.exe" analyze "/output:coverage.xml" "$LATEST_COVERAGE_FILE"
popd > /dev/null
pushd $COVERAGE_REPORT_DIR >/dev/null
"${HOME}/.nuget/packages/microsoft.codecoverage/16.4.0/build/netstandard1.0/CodeCoverage/CodeCoverage.exe" analyze "/output:coverage.xml" "$LATEST_COVERAGE_FILE"
popd >/dev/null

if ! command -v reportgenerator.exe > /dev/null; then
if ! command -v reportgenerator.exe >/dev/null; then
echo "reportgenerator not installed. Skipping generation of HTML reports"
echo "To install: "
echo " % dotnet tool install --global dotnet-reportgenerator-globaltool"
Expand Down Expand Up @@ -340,49 +370,12 @@ DOWNLOAD_DIR="${REPO_ROOT}/_downloads/${RUNTIME_ID}/netcore2x"
PACKAGE_DIR="${REPO_ROOT}/_package/${RUNTIME_ID}"
REPORT_DIR="${REPO_ROOT}/_reports/${RUNTIME_ID}"

if [[ (! -d "${DOTNETSDK_INSTALLDIR}") || (! -e "${DOTNETSDK_INSTALLDIR}/.${DOTNETSDK_VERSION}") || (! -e "${DOTNETSDK_INSTALLDIR}/dotnet") ]]; then

# Download dotnet SDK to ../_dotnetsdk directory
heading "Install .NET SDK"

# _dotnetsdk
# \1.0.x
# \dotnet
# \.1.0.x
echo "Download dotnetsdk into ${DOTNETSDK_INSTALLDIR}"
rm -Rf "${DOTNETSDK_DIR}"

# run dotnet-install.ps1 on windows, dotnet-install.sh on linux
if [[ "${CURRENT_PLATFORM}" == "windows" ]]; then
ext="ps1"
else
ext="sh"
fi

DOTNET_INSTALL_SCRIPT_NAME="dotnet-install.${ext}"
DOTNET_INSTALL_SCRIPT_PATH="./Misc/${DOTNET_INSTALL_SCRIPT_NAME}"

if [[ ! -e "${DOTNET_INSTALL_SCRIPT_PATH}" ]]; then
curl -sSL "https://dot.net/v1/${DOTNET_INSTALL_SCRIPT_NAME}" -o "${DOTNET_INSTALL_SCRIPT_PATH}"
fi

if [[ "${CURRENT_PLATFORM}" == "windows" ]]; then
echo "Convert ${DOTNETSDK_INSTALLDIR} to Windows style path"
sdkinstallwindow_path=${DOTNETSDK_INSTALLDIR:1}
sdkinstallwindow_path=${sdkinstallwindow_path:0:1}:${sdkinstallwindow_path:1}
architecture=$( echo $RUNTIME_ID | cut -d "-" -f2)
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}"
else
bash "${DOTNET_INSTALL_SCRIPT_PATH}" --version ${DOTNETSDK_VERSION} --install-dir "${DOTNETSDK_INSTALLDIR}" --no-path || checkRC "${DOTNET_INSTALL_SCRIPT_NAME}"
fi

echo "${DOTNETSDK_VERSION}" > "${DOTNETSDK_INSTALLDIR}/.${DOTNETSDK_VERSION}"
fi
restore_dotnet_install_script
restore_sdk_and_runtime

heading ".NET SDK to path"

echo "Adding .NET to PATH (${DOTNETSDK_INSTALLDIR})"
export PATH=${DOTNETSDK_INSTALLDIR}:$PATH
echo "Adding .NET SDK to PATH (${DOTNET_DIR})"
export PATH=${DOTNET_DIR}:$PATH
echo "Path = $PATH"
echo ".NET Version = $(dotnet --version)"

Expand All @@ -407,21 +400,21 @@ if [[ "$CURRENT_PLATFORM" == 'windows' ]]; then
fi

case $DEV_CMD in
"build") cmd_build;;
"b") cmd_build;;
"test") cmd_test;;
"t") cmd_test;;
"testl0") cmd_test_l0;;
"l0") cmd_test_l0;;
"testl1") cmd_test_l1;;
"l1") cmd_test_l1;;
"layout") cmd_layout;;
"l") cmd_layout;;
"package") cmd_package;;
"p") cmd_package;;
"hash") cmd_hash;;
"report") cmd_report;;
*) echo "Invalid command. Use (l)ayout, (b)uild, (t)est, test(l0), test(l1), or (p)ackage.";;
"build") cmd_build ;;
"b") cmd_build ;;
"test") cmd_test ;;
"t") cmd_test ;;
"testl0") cmd_test_l0 ;;
"l0") cmd_test_l0 ;;
"testl1") cmd_test_l1 ;;
"l1") cmd_test_l1 ;;
"layout") cmd_layout ;;
"l") cmd_layout ;;
"package") cmd_package ;;
"p") cmd_package ;;
"hash") cmd_hash ;;
"report") cmd_report ;;
*) echo "Invalid command. Use (l)ayout, (b)uild, (t)est, test(l0), test(l1), or (p)ackage." ;;
esac

popd
Expand Down
Loading

0 comments on commit 42229c7

Please sign in to comment.