Chris Simeone
Chris Simeone

Reputation: 1205

Missing Blazor WebAssembly app template for Visual Studio for Mac

I am trying to create a Blazor WebAssembly app using the latest build of Visual Studio for Mac (v8.4.6 build 36).

I have .NET Core 3.1 SDK installed.

I also installed the latest Blazor WebAssembly 3.2.0 Preview 1 by running:

dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.2.0-preview1.20073.1.

The output log shows it installed successfully:

Templates                                         Short Name               Language          Tags                                 
----------------------------------------------------------------------------------------------------------------------------------
Blazor Server App                                 blazorserver             [C#]              Web/Blazor                           
Blazor WebAssembly App                            blazorwasm               [C#]              Web/Blazor/WebAssembly

However, the Blazor WebAssembly App template does not show up in Visual Studio for Mac, even after restarting:

enter image description here And if I create a Blazor WebAssembly app from the CLI as follows, it builds but does not run:

dotnet new blazorwasm
dotnet build
dotnet run

And if I try to run it in Visual Studio for Mac I get this error: Cannot open assembly '/Users/my.username/projects/blazor/BlazerWasm/bin/Debug/netstandard2.1/BlazerWasm.exe': No such file or directory.

Is Visual Studio for Mac not able to build or run Blazor WebAssembly apps, or am I missing something?

Upvotes: 5

Views: 2627

Answers (3)

Chris Simeone
Chris Simeone

Reputation: 1205

**

Microsoft has released a fix for this issue!

**

Support for Blazor WebAssembly projects has been added in the 8.6 release of Visual Studio for Mac. You can update by installing the latest from https://visualstudio.com/mac or updating to the Stable channel using the Visual Studio > Check for Updates… menu.

Ultimately this update worked. However when trying to run the Blazor WebAssembly the very first time I got the following error:

The ASP.NET Core developer certificate is in an invalid state. To fix this issue, run the following commands to remove all existing ASP.NET Core development certificates and create a new untrusted developer certificate.

dotnet dev-certs https --clean
dotnet dev-certs https
dotnet dev-certs https --trust

I followed the instructions running the three commands above and that resolved my error. FYI, the first of the three commands may take a few minutes and you may not see any output activity immediately.

Now I can build a run Blazor WebAssembly in Version 8.6 of Visual Studio for Mac.

For more info see the post I created in the Visual Studio Developer Community:

Upvotes: 1

Chris Simeone
Chris Simeone

Reputation: 1205

Currently, Visual Studio for Mac does not have the ability to create WebAssembly apps using a template. It can however build WebAssembly apps.

To work around this limitation I use the CLI for create and run WebAssembly apps.

» To create the WebAssembly apps from the CLI I use:

dotnet new blazorwasm -n NameOfMyProject

» Now I can edit and build the app using Visual Studio for Mac.

» To run the app from the CLI. I cd into the project directory and run:

dotnet run

Now I can load the app in a browser and edit and test my code changes. I even noticed that "hot reload" works.

I opened an issue with Microsoft Visual Studio Feedback System. A senior product manager replied 4 days ago with this message: "We have started working on adding support for Blazor Web Assembly."

In case you're interested, here is the link to that request: https://developercommunity.visualstudio.com/content/problem/925026/missing-blazor-webassembly-app-template-for-visual.html

Upvotes: 1

Chefty
Chefty

Reputation: 149

I just had the same issue and might have a workaround for you. I did exactly the same command:

dotnet new blazorwasm -n NameOfMyProject

Then I just opened Visual Studio and used "open project or solution" to open the .csproj. From the IDE interface you can build and run without problem.

Cheers,

Chefty

Upvotes: 1

Related Questions