dotnet的移除-->安装 升级

之所以要升级dotnet 是因为项目中报了如下错误

意思就是版本低了

为了升级 我先要把之前的移除掉(用脚本移除)

#!/usr/bin/env bash
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

current_user=$(whoami)
if [ $current_user != "root" ]; then
    echo "$(basename "$0") uninstallation script requires superuser privileges to run"
    exit 1
fi

# this is the common suffix for all the dotnet pkgs
dotnet_pkg_name_suffix="com.microsoft.dotnet"
dotnet_install_root="/usr/local/share/dotnet"
dotnet_path_file="/etc/paths.d/dotnet"

remove_dotnet_pkgs(){
    installed_pkgs=($(pkgutil --pkgs | grep $dotnet_pkg_name_suffix))

    for i in "${installed_pkgs[@]}"
    do
        echo "Removing dotnet component - "$i""
        pkgutil --force --forget "$i"
    done
}

remove_dotnet_pkgs
[ "$?" -ne 0 ] && echo "Failed to remove dotnet packages." && exit 1

echo "Deleting install root - $dotnet_install_root"
rm -r "$dotnet_install_root"
rm "$dotnet_path_file"

echo "dotnet packages removal succeeded."
exit 0

运行脚本的过程 遇到了权限问题

1.Mac新手不会制作脚本文件,没关系打开文本编辑器 把上面的脚本代码粘贴进去,另存为xx.sh文件,.sh文件代表的就是shell文件,保存之后如果不知道怎么在Terminal里执行,可以直接把文件拖到里面回车进行执行。
2.你还有可能遇到 permission denied: ./xx.sh,权限不够 修改脚本文件的权限 
chmod 777 + 脚本文件夹路径
3.即便权限修改成功了,你还有可能会遇到 xx.sh uninstallation script requires superuser privileges to run,没关系 我们可以在脚本文件前面加上sudo 超级权限。 sudo+ 脚本文件夹路径

成功之后到官网下载安装就行了

参考:http://www.jianshu.com/p/b836f04d5817

原文地址:https://www.cnblogs.com/dlwj/p/5913284.html