Base solution for your next web application
Open Closed

Developing on Mac OSX - how I got it setup/working... #5117


User avatar
0
dparizek created

Sharing this in case it helps... how I set up to use ASP.NET Zero on my mac (macOs High Sierra)...

Running ASP.NET Zero on Mac

Install Visual Studio for Mac: <a class="postlink" href="https://www.microsoft.com/net/download/macos">https://www.microsoft.com/net/download/macos</a> Install Visual Studio Code: <a class="postlink" href="https://code.visualstudio.com/">https://code.visualstudio.com/</a> Install .net core SDK: <a class="postlink" href="https://www.microsoft.com/net/download/macos">https://www.microsoft.com/net/download/macos</a>

From ASP.Net Zero download the ASP.NET CORE & Angular latest project version (5.4.1 at this writing) with .NET Core 2.0 as chosen framework and do not check one solution.

In the terminal, go to base_folder/angular and

yarn

(after installing latest: • yarn, in my case version 1.6.0 (<a class="postlink" href="https://yarnpkg.com/lang/en/docs/install/#mac-stable">https://yarnpkg.com/lang/en/docs/install/#mac-stable</a>, I used HomeBrew) • and I use nvm with node version 8.11.1 (<a class="postlink" href="https://github.com/creationix/nvm">https://github.com/creationix/nvm</a> • and angular cli (<a class="postlink" href="https://cli.angular.io/">https://cli.angular.io/</a>)

Next we open app in Visual Studio for Mac. For starters, I opened the Web solution only, under base_folder/aspnet-core

Set Web.Host project as Startup Project (right click on Web.Host project in Solution Explorer and you will see the option)

Build all.

I used a SQL database on Azure, set up in Azure Portal, and there got connection string like this, into base_folder/ aspnet-core/appsettings.json:

"ConnectionStrings": {
	      "Default": "Server=tcp:research1server.database.windows.net,1433;Initial Catalog={my db name};Persist Security Info=False;User ID={my_id};Password={my password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"},

Note you have to get your IPv4 address (e.g. <a class="postlink" href="https://www.whatismyip.com/">https://www.whatismyip.com/</a>) and in Azure Portal click on your database, then the "Set server firewall" button, then create a rule for your IP address (or range of addresses) and Save. Otherwise when you start-up you will see a Connection Refused error in the browser console.

Next we open app in Visual Studio for Mac. For starters, I opened the Web Solution only, under base_folder/aspnet-core

Set Web.Host project as Startup Project (right click on Web.Host project in Solution Explorer and you will see the option)

Now we want to get EF for dotnet. Initially, I used my window machine to do the first database update/migration/initialization on the Azure database instance. But now exploring how to do on Mac:

Go here: <a class="postlink" href="https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet">https://docs.microsoft.com/en-us/ef/cor ... cli/dotnet</a> and see Installing the Tools section.

Edit the Web.Host project file (right click project name and there is an Edit File option) and add following:
<ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> </ItemGroup>

Then back in Terminal:

dotnet add package Microsoft.EntityFrameworkCore.Design 
	dotnet restore

Check your dotnet ef install:

dotnet ef

And you should see a nice ascii unicorn:

Run the project in Visual Studio for Mac, it should take you to <a class="postlink" href="http://localhost:5000/swagger/">http://localhost:5000/swagger/</a> and that worked for me.

Then go to base_folder/angular and:

npm start

Wait, then navigate in browser to <a class="postlink" href="http://localhost:4200/">http://localhost:4200/</a>

And first it did not work for me because I had to set up the firewall rule for Azure, as above.

Then it did not work for me because the client side, according to the browser console, was trying to go to port 22742. But my server side was going to 5000 even though I did not set that anywhere, and appsettings.json seemed to only refer to 22742.

So using Visual Studio Code, I searched the angular project and replaced all instances of 22742 with 5000.

Then… it finally worked! (-:

There is no Package Manager Console in Visual Studio for Mac, so in Terminal you can Add-Migration:

dotnet ef migrations add InitialCreate

Or Update-Database:

dotnet ef database update

When you need to update service-proxies.ts then from angular directory after/while Web.Host project is up and running:

./node_modules/.bin/nswag run

For RAD tool on Mac, there is no Visual Studio extension to create the JSON input file, you create it manually. Which can be faster actually than field by field in GUI. Then run:

dotnet AspNetZeroRadTool.dll YourEntity.Json

(from <a class="postlink" href="https://aspnetzero.com/Documents/Development-Guide-Rad-Tool-Mac-Linux">https://aspnetzero.com/Documents/Develo ... -Mac-Linux</a>)

If you want to use VS Code on Mac without Visual Studio Mac, this is useful to set Startup Project... <a class="postlink" href="https://stackoverflow.com/questions/46705521/how-do-i-designate-a-startup-project-in-vs-code">https://stackoverflow.com/questions/467 ... in-vs-code</a>


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @dparizek awesome :),

    I think this must be an official document.

  • User Avatar
    0
    alirizaadiyahsi created

    +1

  • User Avatar
    0
    dparizek created

    ok, I will add as PR to documentation repo on Github.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @dparizek Thanks, that's awesome :)