You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac版Visual Studio如何搭建项?脚手架创建Controller遇阻咨询

Hey there! I’ve been right where you are—following a C# development course on a Mac, staring at Windows VS steps that don’t translate perfectly. It’s frustrating, but we’ve got this covered. Let’s break down your questions and find solutions that work for your setup:

1. Better Tools for C# on Mac

First, let’s talk tools that’ll make your life easier:

  • Visual Studio for Mac: It’s Microsoft’s official Mac IDE, and while it’s not identical to the Windows version, it has built-in support for scaffolding and EF Core once you set up the right packages.
  • JetBrains Rider: This is my go-to recommendation for Mac. It’s incredibly polished, has near-parity with Windows VS’s scaffolding workflows, and handles EF Core setup seamlessly without extra hoops.
  • VS Code: If you prefer a lighter editor, it works great too—you just need to install a few key plugins to match the course’s functionality.
2. Fixing EF Core & Model Folder Setup

You’re already on the right track with manually adding EF Core and creating a Models folder. To make sure you’ve got all the necessary packages, run these commands in your project’s terminal:

# Add base EF Core package
dotnet add package Microsoft.EntityFrameworkCore
# Add your database provider (example for SQL Server; swap for SQLite/PostgreSQL if needed)
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
# Add tools for migrations and scaffolding
dotnet add package Microsoft.EntityFrameworkCore.Tools

Creating the Models folder and empty classes manually is totally normal on Mac—just right-click your project in your IDE and select "New Folder" > "New Class" to match what the course does.

3. Generating Controllers with Scaffolding

This is where Mac setups differ most from Windows VS, but here’s how to do it in each tool:

Visual Studio for Mac

  1. Right-click your project in the Solution Explorer
  2. Hover over Add > select New Scaffolded Item
  3. Choose MVC Controller with views, using Entity Framework
  4. Follow the wizard to select your model class, DbContext, and name your controller
    • If you don’t see this option, install the global scaffolding tool first: dotnet tool install -g dotnet-aspnet-codegenerator

JetBrains Rider

  1. Right-click the Controllers folder in your project
  2. Select Add > Controller
  3. Pick MVC Controller with EF Core Views from the list
  4. Rider’s wizard will auto-detect your models and DbContext—just fill in the controller name and hit create. No extra commands needed!

VS Code

  1. First, install the C# Dev Kit plugin (it’s Microsoft’s official plugin for C# in VS Code, and it’s non-negotiable)
  2. Install the global scaffolding tool if you haven’t: dotnet tool install -g dotnet-aspnet-codegenerator
  3. Install the design package for scaffolding: dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
  4. Run this terminal command to generate your controller (replace the placeholders with your actual names):
    dotnet aspnet-codegenerator controller -name ProductController -m Product -dc AppDbContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries
    
4. Must-Have Plugins/Packages
  • For VS Code:
    • C# Dev Kit: Provides IntelliSense, debugging, and project management tools
    • Entity Framework Core Tools: Lets you run EF migrations and commands directly in the editor
  • For all tools:
    • Microsoft.VisualStudio.Web.CodeGeneration.Design: Required for scaffolding controllers/views
    • dotnet-aspnet-codegenerator: Global tool that powers the scaffolding functionality

Overall, Rider is the closest you’ll get to the Windows VS experience out of the box, but Visual Studio for Mac or VS Code with the right plugins will work just fine once you set them up. You’re already doing the hard part by adapting to the Mac workflow—these tweaks will make it feel much more familiar.

内容的提问来源于stack exchange,提问作者miguelopezv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:30:36