ASP.NET Core SPA Templates on Mac

While installing Visual Studio for Mac, which was launched on the Visual Studio 20th anniversary, I assumed it would set up the .NET core SDK but to my surprise it didn't - since terminal didn't allow me to do

$ dotnet new

I downloaded and installed the .NET Core SDK (.pkg) from and then it worked. However in release notes it mentions that openssl needs to be installed and i did via brew but the dotnet command still did not let me install the ASP.NET Core SPA Templates using 

$ dotnet new --install Microsoft.AspNetCore.SpaTemplates::*

 and presented me with errors like

A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once.
Decompressing 100% 4148 ms
Expanding 100% 4502 ms
Getting ready...
  Restoring packages for .templateengine/dotnetcli/v1.0.1/scratch/restore.csproj...
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error : Unable to load the service index for source [/.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error :   The type initializer for 'System.Net.Http.CurlHandler' threw an exception. [.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error :   The type initializer for 'Http' threw an exception. [.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error :   The type initializer for 'HttpInitializer' threw an exception. [.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error :   The type initializer for 'CryptoInitializer' threw an exception. [.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error :   Unable to load DLL 'System.Security.Cryptography.Native.OpenSsl': The specified module could not be found. [.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]
/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error :    (Exception from HRESULT: 0x8007007E) [.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj]

which essentially implied that something was wrong with the openssl installation. So next logical step was to fix that and the clue was the name of the file System.Security.Cryptography.Native.OpenSsl . I next ran the command 

$ sudo install_name_tool -add_rpath /usr/local/opt/openssl/lib /usr/local/share/dotnet/shared/Microsoft.NETCore.App/1.1.1/System.Security.Cryptography.Native.OpenSsl.dylib

and retried to install the SPA templates and it ended with the happy message 

Installing System.IO.Compression 4.1.0.
  Installing System.Xml.ReaderWriter 4.0.11.
  Generating MSBuild file /Users/digvijay/.templateengine/dotnetcli/v1.0.1/scratch/obj/restore.csproj.nuget.g.props.
  Generating MSBuild file /Users/digvijay/.templateengine/dotnetcli/v1.0.1/scratch/obj/restore.csproj.nuget.g.targets.
  Writing lock file to disk. Path: /Users/digvijay/.templateengine/dotnetcli/v1.0.1/scratch/obj/project.assets.json
  Restore completed in 11.61 sec for /Users/digvijay/.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj.
  NuGet Config files used:
  Feeds used:
      111 package(s) to /Users/digvijay/.templateengine/dotnetcli/v1.0.1/scratch/restore.csproj

Which was fun! However - it ended with 

/usr/local/share/dotnet/sdk/1.0.1/NuGet.targets(97,5): error : Too many open files 

Arggggggh .....

The solution was simply to run 

$ ulimit -n 512

And then the template installation did actually happen. Next I am up for writing my first ever Aurelia single page app. I hope someone stuck in same situation as me would find it useful!

So until next time!


Comments are closed