This document was created to supplement the Code Fellows ASP.NET Core Curriculum for macOS users.
Pros | Cons | |
---|---|---|
BootCamp |
|
|
Parallels/VMware Fusion |
|
|
Visual Studio for macOS |
|
|
Follow these directions for installing the SQL Server on macOS.
- For Step 5, the latest SQL Server container image can be checked here.
- For Step 5, make sure to name your container with the
--name sql_server_demo
parameter in order to start and stop container from Terminal later. - Install Azure Data Studio for Mac here.
- If you are having trouble opening the app from macOS Catalina, open the app by following these directions.
This section of the guide supplements Default MVC Application.
Since the Package Manager Console feature is not available on Visual Studio for Mac, we will use .NET Command-Line Interface (.NET CLI). .NET CLI is used to perform design-time development tasks such as migration or updates for a model based on an existing database.
- Install
dotnet ef
globally by entering the following into your Terminal:dotnet tool install --global dotnet-ef
- Install the latest
Microsoft.EntityFrameworkCore.Design
package by entering the following into your Terminal:dotnet add package Microsoft.EntityFrameworkCore.Design
- Check if the server is connected. This can be checked by entering the following into your Terminal:
Docker ps
- If Docker server is not connected, start the server by entering the following into your Terminal:
Docker start CONTAINERNAME
-
Using Terminal, navigate to the project's root folder.
-
Instead of the Connection String from Adding Entity Framework Core and a SQL Database Step 1, add the following Connection Strings to your
appsettings.json
file:"ConnectionStrings": { "DefaultConnection": "Server=localhost;Database=DBNAMEHERE;User=sa;Password=reallyStrongPwd123" }
-
Instead of
Add-Migration initial
from Adding Entity Framework Core and a SQL Database Step 6, enter the following into your Terminal:dotnet ef migrations add initial
Enter thr following into your Terminal when there are multiple databases connected:
dotnet ef migrations add --context DBNAMEHERE initial
-
Instead of
Update-Database
from Adding Entity Framework Core and a SQL Database Step 7, enter the following into your Terminal:dotnet ef database update
Enter thr following into your Terminal when there are multiple databases connected:
dotnet ef database update --context DBNAMEHERE
-
Instead of SQL Server Object Explorer, the database can be checked with Azure Data Studio.
-
To remove a database, enter the following into your Terminal:
dotnet ef database drop -f
Enter the following into your Terminal when there are multiple databases connected:
dotnet ef database drop -f --context DBNAMEHERE
This section of the guide supplements Lab: 12 - Intro to EFCore & APIs.
Follow the below steps to scaffold a controller using a DbContext class.
-
Add required NuGet packages by entering the following into your Terminal:
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design dotnet add package Microsoft.EntityFrameworkCore.Design
-
Install the scaffolding engine by entering the following into your Terminal:
dotnet tool install --global dotnet-aspnet-codegenerator
-
Scaffold a Controller by entering the following into your Terminal:
dotnet aspnet-codegenerator controller -name HotelsController -async -api -m Hotel -dc AsyncInnDbContext -outDir Controllers
-name
is name of the controller-m
is model class to use-dc
is the DbContext class to useoutDir
is the relative output folder path from project where the file are generated
Above commands will create HotelsController in the Controller folder.
This section of the guide supplements How to add User Secrets to .NET Core through Visual Studio.
Since the Manage User Secrets feature is not available on Visual Studio for Mac, we will need to add the secrets manually.
- If
.microsoft
folder has not been created, create a directory~/.microsoft
to store secrets by entering the following into your Terminal:mkdir ~/.microsoft
- Using Terminal, navigate to the project's root folder.
- Enable secret storage by entering the following into your Terminal:
dotnet user-secrets init
- To directly access and update
secrets.json
file, pressCommand + Shift + .
to see hidden files on Mac and navigate to~/.microsoft/usersecrets/<user_secrets_id>/secrets.json
.
This section of the guide supplements Azure DevOps Cheat Sheet - Create a Repo.
- Go to Repos tab and click
Clone
- Clcik
Generate Git Credential
and save the generated password - Copy the HTTPS command
- Enter the following into your Terminal to clone the repo:
git clone repo HTTPS
- When prompted to enter the password, enter the saved password
Follow these directions when there is a merge conflict.
- Using a Mac in a modern .NET world
- How to Install SQL Server on a Mac
- User Secrets in a .NET Core Web App
- Docker Documentation
- Microsoft Documentation - Entity Framework Core tools reference - .NET CLI
- Microsoft Documentation - Migrations
- Microsoft Documentation - Safe storage of app secrets in development in ASP.NET Core
- Microsoft Documentation - Use Git Credential Managers to authenticate to Azure Repos (Didn't work for me)
- Git-Credential-Manager-for-Mac-and-Linux (Didn't work for me)
- Microsoft Documentation - dotnet aspnet-codegenerator
- Microsoft Documentation - Tutorial: Create a web API with ASP.NET Core
- Scaffolding a API Controller Content Added - 29 Jul 2020