5

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?

Chris Simeone
  • 755
  • 1
  • 10
  • 26
  • I found this comment on a post: "Blazor WebAssembly apps are downloaded to the browser as static files and then executed client-side. There isn’t an executable for Blazor WebAssembly apps that you can just run. We do however provide a dev server to facilitate locally hosting the app on your machine, which is how `dotnet run` works." Post link: https://devblogs.microsoft.com/aspnet/blazor-webassembly-3-2-0-preview-1-release-now-available/ – Chris Simeone Feb 21 '20 at 20:51
  • This partially answers my question. When I enter `dotnet run` in the CLI, I can browse to my WebAssembly app on port 5000. When I view the source in the devtools I see several `webassembly` references. So I think the web assembly works. But the Blazor WebAssembly App template should be visible in the IDE. And we should be able to run the app within the IDE so we can then browse to it. I posted my issue with the "Visual Studio Feedback System" and I am waiting on a reply: https://developercommunity.visualstudio.com/content/problem/925026/missing-blazor-webassembly-app-template-for-visual.html – Chris Simeone Feb 21 '20 at 20:58
  • 1
    Visual Studio for Mac does not show templates installed via dotnet install since extra metadata/configuration is needed to enable them in its New Project dialog – Matt Ward Feb 22 '20 at 16:51
  • Microsoft has released a fix for this issue! Support for Blazor WebAssembly projects has been added in Visual Studio for Mac v8.6. See my most recent answer below. – Chris Simeone May 27 '20 at 19:30

3 Answers3

1

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

Chefty
  • 149
  • 1
  • 13
  • Chefty, I have tried that also. The project appears to build in the IDE with no errors, but it will not run. I get this error: `Cannot open assembly '/Users/my.username/Documents/projects/blazor/HelloBlazerWasm/bin/Debug/netstandard2.1/HelloBlazerWasm.exe': No such file or directory.` – Chris Simeone Feb 21 '20 at 20:16
1

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

Chris Simeone
  • 755
  • 1
  • 10
  • 26
1

**

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:

Chris Simeone
  • 755
  • 1
  • 10
  • 26