Skip to content

环境准备

本指南将详细介绍如何配置 Fastdotnet 的开发环境。

💡 想先体验一下? 访问 在线演示 无需安装即可试用!


💻 操作系统支持

Fastdotnet 支持以下操作系统:

  • ✅ Windows 10/11
  • ✅ macOS 12+
  • ✅ Linux (Ubuntu 20.04+, CentOS 8+)

🔧 安装 .NET SDK

Windows

  1. 下载 .NET 10 SDK 安装包

  2. 运行安装程序,按照提示完成安装

  3. 验证安装:

    bash
    dotnet --version
    # 应输出:10.0.x

macOS

使用 Homebrew 安装:

bash
# 安装 Homebrew(如果尚未安装)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# 安装 .NET SDK
brew install --cask dotnet-sdk

# 验证安装
dotnet --version

Linux (Ubuntu)

bash
# 添加 Microsoft 包源
wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb

# 安装 .NET SDK
sudo apt-get update
sudo apt-get install -y dotnet-sdk-10.0

# 验证安装
dotnet --version

📦 安装 Node.js

Windows/macOS

  1. 访问 https://nodejs.org/
  2. 下载 LTS 版本(推荐 18.x 或更高)
  3. 运行安装程序

Linux (Ubuntu)

bash
# 使用 NodeSource 仓库
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# 验证安装
node --version  # 应输出:v18.x.x
npm --version   # 应输出:9.x.x 或更高

🎯 安装 pnpm

pnpm 是一个快速、节省磁盘空间的包管理器。

全局安装

bash
# 使用 npm 安装
npm install -g pnpm

# 或使用 Corepack(Node.js 16.13+ 内置)
corepack enable
corepack prepare pnpm@latest --activate

验证安装

bash
pnpm --version
# 应输出:8.x.x 或更高

配置国内镜像(可选)

如果网络较慢,可以配置国内镜像源:

bash
pnpm config set registry https://registry.npmmirror.com

🗄️ 数据库准备

Fastdotnet 支持多种数据库,你可以选择其中一种:

选项 1:SQLite(推荐用于开发测试)

优点:无需安装,零配置

SQLite 已内置在项目中,无需额外安装。只需在配置文件中设置:

json
{
  "ConnectionStrings": {
    "DefaultConnection": "Data Source=fastdotnet.db"
  }
}

选项 2:SQL Server

Windows

  1. 下载 SQL Server Express(免费版)

  2. 安装 SQL Server Management Studio (SSMS)

    • 用于管理数据库的图形化工具
  3. 连接字符串示例:

    json
    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=localhost;Database=Fastdotnet;Trusted_Connection=True;TrustServerCertificate=True;"
      }
    }

Docker 方式

bash
docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=YourStrong@Passw0rd" \
  -p 1433:1433 --name sqlserver \
  -d mcr.microsoft.com/mssql/server:2022-latest

连接字符串:

Server=localhost,1433;Database=Fastdotnet;User Id=sa;Password=YourStrong@Passw0rd;TrustServerCertificate=True;

选项 3:PostgreSQL

安装

Windows/macOS

Linux (Ubuntu)

bash
sudo apt-get install postgresql postgresql-contrib

Docker 方式

bash
docker run --name postgres \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=Fastdotnet \
  -p 5432:5432 \
  -d postgres:15

连接字符串:

Host=localhost;Database=Fastdotnet;Username=postgres;Password=postgres

选项 4:MySQL

Docker 方式

bash
docker run --name mysql \
  -e MYSQL_ROOT_PASSWORD=root \
  -e MYSQL_DATABASE=Fastdotnet \
  -p 3306:3306 \
  -d mysql:8.0

连接字符串:

Server=localhost;Database=Fastdotnet;Uid=root;Pwd=root;

🛠️ IDE 配置

Visual Studio 2022(推荐 Windows 用户)

  1. 下载 Community 版(免费)

  2. 安装时勾选工作负载:

    • ✅ ASP.NET 和 Web 开发
    • ✅ .NET 桌面开发(可选)
  3. 打开解决方案文件:

    backend/Fastdotnet.sln

JetBrains Rider(跨平台)

  1. 下载 Rider

  2. 打开项目目录即可

VS Code(轻量级)

  1. 下载 VS Code

  2. 安装扩展:

    • C# Dev Kit
    • C# Extensions
    • Vue Language Features (Volar)
    • ESLint
    • Prettier

✅ 环境验证

完成所有安装后,运行以下命令验证环境:

bash
# 检查 .NET
dotnet --version
# 预期输出:10.0.x

# 检查 Node.js
node --version
# 预期输出:v18.x.x 或更高

# 检查 pnpm
pnpm --version
# 预期输出:8.x.x 或更高

# 检查数据库(以 PostgreSQL 为例)
psql --version
# 预期输出:psql (PostgreSQL) 15.x

🐛 常见问题

1. dotnet 命令找不到

Windows

  • 重启命令行窗口
  • 检查环境变量 PATH 中是否包含 .NET 安装路径

macOS/Linux

bash
# 重新加载环境变量
source ~/.bashrc  # 或 ~/.zshrc

# 手动添加 PATH
export PATH=$PATH:/usr/local/share/dotnet

2. pnpm 权限错误

Linux/macOS

bash
# 修复 npm 全局目录权限
sudo chown -R $(whoami) ~/.npm

# 或使用 nvm 管理 Node.js 版本

3. 数据库连接失败

  • 确认数据库服务已启动
  • 检查防火墙设置
  • 验证用户名和密码
  • 查看数据库日志获取详细错误信息

📚 下一步

环境准备完成后,继续学习:

如有问题,欢迎查阅 常见问题 或提交 Issue!

Released under the MIT License.