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:
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.
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.
This is where Mac setups differ most from Windows VS, but here’s how to do it in each tool:
Visual Studio for Mac
- Right-click your project in the Solution Explorer
- Hover over Add > select New Scaffolded Item
- Choose MVC Controller with views, using Entity Framework
- 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
- If you don’t see this option, install the global scaffolding tool first:
JetBrains Rider
- Right-click the Controllers folder in your project
- Select Add > Controller
- Pick MVC Controller with EF Core Views from the list
- 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
- First, install the C# Dev Kit plugin (it’s Microsoft’s official plugin for C# in VS Code, and it’s non-negotiable)
- Install the global scaffolding tool if you haven’t:
dotnet tool install -g dotnet-aspnet-codegenerator - Install the design package for scaffolding:
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design - 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
- 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/viewsdotnet-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

