3

I have a Blazor hosted application with a client (webassembly), server and shared project (from the webassembly hosted template). It runs fine from Visual Studio, but I don't know how to run it from the command line. I've tried:

  1. dotnet run (from the solution, root project and server project directories)
  2. Running the exe built by Visual Studio from the netcoreapp3.1 directory under the server project
  3. Running the dll (using the dotnet command) from the netcoreapp3.1 directory under the server project
  4. Both 2 and 3 but from the publish directory

All of them fail. Does anyone know how I would run this from the command line? I want to push it to Cloud Foundry but cannot without knowing how to run it.

10
  • Item 2 works for me. Describe what you see. Just "All of them fail" isn't helpful. Commented Mar 9, 2020 at 12:44
  • 1
    And that helped solve my issue.... I was about to put the stack trace into my question and read it again and it suddenly hit me what was wrong. Stupid dev vs release bug in my code. Commented Mar 9, 2020 at 13:03
  • @henk-holterman - I lied.... the server part is running when I run the server exe now, but it's not finding my pages. Are you having that issue? Did your page come up ok? My main layout and nav menu come up, but the page says "Sorry, there's nothing at this address.". Commented Mar 9, 2020 at 13:09
  • From the standard template out it works fine. Did you add any Authorization related code? Commented Mar 9, 2020 at 13:54
  • I created a new Blazor client-side app with ASP.Net Core hosting, did a "dotnet build -c Release" and "dotnet publish -c Release" from the solution directory, went into the server\bin\release\netcoreapp3.1\publish directory, ran the EXE, opened a browser to localhost:5000 and got the same message as above ("Sorry, there's nothing at this address"). Commented Mar 9, 2020 at 14:01

2 Answers 2

3

On .NET 5, I was able to get my Blazor Client-Side App to run by using dotnet run

cd C:\path\to\source\server
dotnet run

It should say something like Now listening on https://localhost:5001, and you should be able to navigate there in your browser.

If that doesn't work, you may need to configure your SSL cert. I had to add this "Key" section to my appsettings.json. Note, this applies to published and release builds - more info here

  "IdentityServer": {
    "Clients": {
      "BlazorApp.Client": {
        "Profile": "IdentityServerSPA"
      }
    },
    "Key": {
        "Type": "Store",
        "StoreName": "My",
        "StoreLocation": "CurrentUser",
        "Name": "CN=localhost"
      }
  },

You can view your certs by using ls

ls Cert:\CurrentUser\My\{thumbprint}

Just use tab completion to figure out the path

Sign up to request clarification or add additional context in comments.

1 Comment

You just have saved my day, thanks. This also works fine for pure client-side Blazor WASM projects.
1

A hosted Blazor app (that is, an app with a Blazor client part as well as a server Web API part) is created this way in the Windows command prompt:

md NameOfYourApp

cd NameOfYourApp

dotnet new blazorwasm --hosted

This creates a Blazor app with Client, Server, and Shared folders under NameOfYourApp.

Using dotnet run within the Client or Server folders won't work properly. Instead, to run your app from the command line, run the Server .exe file created when you build:

dotnet build

cd Server\bin\Debug\net5.0

NameOfYourApp.Server.exe

(If you don't switch to the directory of the .exe, your app won't be able to find the appsettings.json file.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.