.NET Installation Skill
.NET 安装指南
Automated .NET SDK and runtime installation with intelligent platform detection, version management, and troubleshooting guidance.
自动化的.NET SDK与运行时安装,包含智能平台检测、版本管理和故障排查指导。
Check Current Installation
检查当前安装情况
Output: 8.0.100
输出: 8.0.100
Output: 8.0.100 [/usr/local/share/dotnet/sdk]
输出: 8.0.100 [/usr/local/share/dotnet/sdk]
Output: Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
输出: Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
The skill automatically detects your operating system and recommends the best installation method:
本指南会自动检测你的操作系统,并推荐最优安装方式:
Detected: macOS 14.2 (arm64)
检测到: macOS 14.2 (arm64)
Recommended: Official installer package (.pkg)
推荐: 官方安装包 (.pkg)
Alternative: Homebrew (brew install dotnet)
备选: Homebrew (brew install dotnet)
Quick Install (Recommended Methods)
快速安装(推荐方式)
Install .NET 8 SDK (LTS)
安装.NET 8 SDK(长期支持版)
winget install Microsoft.DotNet.SDK.8
winget install Microsoft.DotNet.SDK.8
Output: 8.0.100
输出: 8.0.100
**macOS (Official Installer)**:
```bash
**macOS(官方安装器)**:
```bash
Download and install from:
下载并安装:
Or use Homebrew:
或使用Homebrew:
Output: 8.0.100
输出: 8.0.100
**Linux (Ubuntu/Debian)**:
```bash
**Linux(Ubuntu/Debian)**:
```bash
Add Microsoft package repository
添加微软软件源
Install .NET 8 SDK
安装.NET 8 SDK
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
Output: 8.0.100
输出: 8.0.100
SDK vs Runtime Decision
SDK与运行时选择
Install SDK when:
- Building applications
- Developing locally
- Running or
- Need the complete toolchain
Install Runtime only when:
- Deploying production apps
- Running pre-compiled applications
- Minimizing installation size
- Production servers
以下情况安装SDK:
- 构建应用程序
- 本地开发
- 运行或命令
- 需要完整工具链
以下情况仅安装运行时:
- 部署生产环境应用
- 运行预编译应用
- 最小化安装体积
- 生产服务器
Install SDK (includes runtime)
安装SDK(包含运行时)
sudo apt-get install dotnet-sdk-8.0
sudo apt-get install dotnet-sdk-8.0
Install runtime only (smaller)
仅安装运行时(体积更小)
sudo apt-get install aspnetcore-runtime-8.0 # For ASP.NET Core apps
sudo apt-get install dotnet-runtime-8.0 # For console apps
sudo apt-get install aspnetcore-runtime-8.0 # 适用于ASP.NET Core应用
sudo apt-get install dotnet-runtime-8.0 # 适用于控制台应用
Windows Installation Methods
Windows安装方式
Method 1: WinGet (Recommended)
方式1:WinGet(推荐)
List available .NET versions
列出可用的.NET版本
winget search Microsoft.DotNet.SDK
winget search Microsoft.DotNet.SDK
Install .NET 8 SDK (LTS)
安装.NET 8 SDK(长期支持版)
winget install Microsoft.DotNet.SDK.8
winget install Microsoft.DotNet.SDK.8
Install specific version
安装特定版本
winget install Microsoft.DotNet.SDK.8 --version 8.0.100
winget install Microsoft.DotNet.SDK.8 --version 8.0.100
Update existing installation
更新已安装版本
winget upgrade Microsoft.DotNet.SDK.8
winget upgrade Microsoft.DotNet.SDK.8
Method 2: Visual Studio Installer
方式2:Visual Studio安装器
Visual Studio 2022 detected at: C:\Program Files\Visual Studio\2022\Community
检测到Visual Studio 2022位于: C:\Program Files\Visual Studio\2022\Community
.NET 8 SDK available via: Modify Installation → .NET desktop development
可通过以下方式获取.NET 8 SDK:修改安装 → .NET桌面开发
Installation steps:
1. Launch Visual Studio Installer
2. Click "Modify" on your installation
3. Select ".NET desktop development" workload
4. Apply changes
安装步骤:
1. 启动Visual Studio安装器
2. 点击你的安装项旁的"修改"
3. 选择".NET桌面开发"工作负载
4. 应用更改
Method 3: Standalone Installer
方式3:独立安装器
File: dotnet-sdk-8.0.100-win-x64.exe
文件: dotnet-sdk-8.0.100-win-x64.exe
SHA512: [verification hash]
SHA512: [校验哈希值]
Run installer (GUI)
运行安装器(图形界面)
.\dotnet-sdk-8.0.100-win-x64.exe
.\dotnet-sdk-8.0.100-win-x64.exe
.\dotnet-sdk-8.0.100-win-x64.exe /install /quiet /norestart
.\dotnet-sdk-8.0.100-win-x64.exe /install /quiet /norestart
Method 4: PowerShell Script
方式4:PowerShell脚本
Download install script
下载安装脚本
Install latest .NET 8 SDK
安装最新.NET 8 SDK
.\dotnet-install.ps1 -Channel 8.0
.\dotnet-install.ps1 -Channel 8.0
Install to custom location
安装到自定义路径
.\dotnet-install.ps1 -Channel 8.0 -InstallDir "C:\Program Files\dotnet"
.\dotnet-install.ps1 -Channel 8.0 -InstallDir "C:\Program Files\dotnet"
Install runtime only
仅安装运行时
.\dotnet-install.ps1 -Channel 8.0 -Runtime dotnet
.\dotnet-install.ps1 -Channel 8.0 -Runtime dotnet
macOS Installation Methods
macOS安装方式
Method 1: Official Installer Package (Recommended)
方式1:官方安装包(推荐)
Detected: Apple Silicon (arm64)
检测到: Apple Silicon (arm64)
Recommended: dotnet-sdk-8.0.100-osx-arm64.pkg
推荐: dotnet-sdk-8.0.100-osx-arm64.pkg
Double-click .pkg file to install
双击.pkg文件进行安装
Verify installation location
验证安装路径
Output: /usr/local/share/dotnet/dotnet
输出: /usr/local/share/dotnet/dotnet
Method 2: Homebrew
方式2:Homebrew
Install Homebrew (if needed)
安装Homebrew(如未安装)
Install .NET SDK
安装.NET SDK
Install specific version (if available)
安装特定版本(若可用)
Update existing installation
更新已安装版本
Method 3: Install Script
方式3:安装脚本
Download install script
下载安装脚本
Install latest .NET 8 SDK
安装最新.NET 8 SDK
./dotnet-install.sh --channel 8.0
./dotnet-install.sh --channel 8.0
Install to custom location
安装到自定义路径
./dotnet-install.sh --channel 8.0 --install-dir ~/.dotnet
./dotnet-install.sh --channel 8.0 --install-dir ~/.dotnet
echo 'export PATH="$HOME/.dotnet:$PATH"' >> ~/.zshrc
source ~/.zshrc
echo 'export PATH="$HOME/.dotnet:$PATH"' >> ~/.zshrc
source ~/.zshrc
Linux Installation Methods
Linux安装方式
Ubuntu/Debian
Ubuntu/Debian
Ubuntu 22.04 LTS
Ubuntu 22.04 LTS
Ubuntu 20.04 LTS
Ubuntu 20.04 LTS
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
sudo apt-get update
sudo apt-get install -y dotnet-sdk-8.0
Install runtime only
仅安装运行时
sudo apt-get install -y aspnetcore-runtime-8.0
sudo apt-get install -y aspnetcore-runtime-8.0
Fedora/RHEL/CentOS
Fedora/RHEL/CentOS
sudo dnf install dotnet-sdk-8.0
sudo dnf install dotnet-sdk-8.0
RHEL/CentOS (register Microsoft repository first)
RHEL/CentOS(先注册微软软件源)
Install from official repositories
从官方软件源安装
sudo pacman -S dotnet-sdk
sudo pacman -S dotnet-sdk
Install runtime only
仅安装运行时
sudo pacman -S aspnet-runtime
sudo pacman -S aspnet-runtime
Add Microsoft repository
添加微软软件源
./dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet
./dotnet-install.sh --channel 8.0 --install-dir /usr/share/dotnet
export PATH="$PATH:/usr/share/dotnet"
export PATH="$PATH:/usr/share/dotnet"
Version Management with global.json
使用global.json管理版本
Control which .NET SDK version your project uses:
Create global.json for .NET 8
创建针对.NET 8的global.json
dotnet new globaljson --sdk-version 8.0.100
dotnet new globaljson --sdk-version 8.0.100
View current global.json
查看当前global.json
cat global.json
```json
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestPatch"
}
}
Roll-forward policies:
- - Use latest patch (8.0.x)
- - Use latest feature band (8.x.x)
- - Use latest minor (x.x.x)
- - Exact version required
cat global.json
```json
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestPatch"
}
}
向前兼容策略:
- - 使用最新补丁版本(8.0.x)
- - 使用最新功能版本(8.x.x)
- - 使用最新次要版本(x.x.x)
- - 必须使用精确版本
SDK vs Runtime Architecture
SDK与运行时架构
SDK Components:
.NET SDK 8.0.100
├── Runtime (8.0.0)
├── Compiler (Roslyn)
├── CLI Tools (dotnet build, run, publish)
├── Templates (dotnet new)
└── MSBuild
Runtime-Only Components:
.NET Runtime 8.0.0
├── CoreCLR (execution engine)
├── Base Class Libraries
└── Framework assemblies
Size comparison:
- SDK: ~200-400 MB
- Runtime: ~50-150 MB
SDK组件:
.NET SDK 8.0.100
├── 运行时 (8.0.0)
├── 编译器 (Roslyn)
├── CLI工具 (dotnet build, run, publish)
├── 模板 (dotnet new)
└── MSBuild
仅运行时组件:
.NET Runtime 8.0.0
├── CoreCLR(执行引擎)
├── 基础类库
└── 框架程序集
体积对比:
- SDK: ~200-400 MB
- 运行时: ~50-150 MB
Installing Multiple Versions Side-by-Side
多版本并行安装
.NET supports multiple versions installed simultaneously:
List all installed SDKs
列出所有已安装的SDK
6.0.420 [/usr/local/share/dotnet/sdk]
6.0.420 [/usr/local/share/dotnet/sdk]
7.0.410 [/usr/local/share/dotnet/sdk]
7.0.410 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]
8.0.100 [/usr/local/share/dotnet/sdk]
Install additional versions
安装额外版本
sudo apt-get install dotnet-sdk-7.0 # Adds to existing installation
sudo apt-get install dotnet-sdk-7.0 # 添加到现有安装中
Project selects version via global.json
项目通过global.json选择版本
cd my-project
cat global.json
cd my-project
cat global.json
{ "sdk": { "version": "7.0.410" } }
{ "sdk": { "version": "7.0.410" } }
Output: 7.0.410 (selected by global.json)
输出: 7.0.410(由global.json指定)
For air-gapped environments or restricted networks:
Download offline installer
下载离线安装器
Select: x64 | Binaries
选择: x64 | Binaries
Extract to destination
解压到目标路径
Expand-Archive dotnet-sdk-8.0.100-win-x64.zip -DestinationPath "C:\Program Files\dotnet"
Expand-Archive dotnet-sdk-8.0.100-win-x64.zip -DestinationPath "C:\Program Files\dotnet"
$env:PATH = "C:\Program Files\dotnet;$env:PATH"
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, "Machine")
$env:PATH = "C:\Program Files\dotnet;$env:PATH"
[Environment]::SetEnvironmentVariable("PATH", $env:PATH, "Machine")
Extract to system location
解压到系统路径
sudo mkdir -p /usr/local/share/dotnet
sudo tar -xzf dotnet-sdk-8.0.100-linux-x64.tar.gz -C /usr/local/share/dotnet
sudo mkdir -p /usr/local/share/dotnet
sudo tar -xzf dotnet-sdk-8.0.100-linux-x64.tar.gz -C /usr/local/share/dotnet
sudo ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/dotnet
sudo ln -s /usr/local/share/dotnet/dotnet /usr/local/bin/dotnet
Docker Installation
Docker安装
Use official .NET SDK image
使用官方.NET SDK镜像
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
Copy and restore project
复制并还原项目
COPY *.csproj ./
RUN dotnet restore
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
COPY . ./
RUN dotnet publish -c Release -o out
Runtime image (smaller)
运行时镜像(体积更小)
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "MyApp.dll"]
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
COPY --from=build /app/out .
ENTRYPOINT ["dotnet", "MyApp.dll"]
Common Troubleshooting
Common Troubleshooting
Verify dotnet location
验证dotnet位置
which dotnet # macOS/Linux
where.exe dotnet # Windows
which dotnet # macOS/Linux
where.exe dotnet # Windows
If not found, add to PATH manually:
若未找到,手动添加到PATH:
macOS/Linux (bash)
macOS/Linux (bash)
echo 'export PATH="$PATH:/usr/local/share/dotnet"' >> ~/.bashrc
source ~/.bashrc
echo 'export PATH="$PATH:/usr/local/share/dotnet"' >> ~/.bashrc
source ~/.bashrc
echo 'export PATH="$PATH:/usr/local/share/dotnet"' >> ~/.zshrc
source ~/.zshrc
echo 'export PATH="$PATH:/usr/local/share/dotnet"' >> ~/.zshrc
source ~/.zshrc
Windows (PowerShell)
Windows (PowerShell)
$env:PATH = "$env:PATH;C:\Program Files\dotnet"
$env:PATH = "$env:PATH;C:\Program Files\dotnet"
SDK Not Found After Installation
安装后SDK未找到
Check installation location
检查安装路径
Look for "Base Path:" in output
在输出中查找"Base Path:"字段
Register installation manually (Linux)
手动注册安装(Linux)
sudo ln -s /usr/local/share/dotnet/dotnet /usr/bin/dotnet
sudo ln -s /usr/local/share/dotnet/dotnet /usr/bin/dotnet
Clear NuGet cache if corrupted
若NuGet缓存损坏,清理缓存
dotnet nuget locals all --clear
dotnet nuget locals all --clear
Remove specific SDK version
移除特定SDK版本
sudo apt-get remove dotnet-sdk-7.0 # Linux
winget uninstall Microsoft.DotNet.SDK.7 # Windows
sudo apt-get remove dotnet-sdk-7.0 # Linux
winget uninstall Microsoft.DotNet.SDK.7 # Windows
Force project to use available SDK
强制项目使用可用SDK
Edit global.json:
编辑global.json:
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMinor" # More permissive
}
}
{
"sdk": {
"version": "8.0.100",
"rollForward": "latestMinor" # 更宽松的兼容策略
}
}
Comprehensive Details: See reference.md for:
- Complete platform-specific installation commands
- Advanced version management strategies
- Enterprise deployment patterns
- CI/CD integration examples
- Performance optimization tips
Official Documentation:
详细内容: 查看reference.md获取:
- 完整的平台专属安装命令
- 高级版本管理策略
- 企业级部署模式
- CI/CD集成示例
- 性能优化技巧
官方文档: