[英]Running Blazor Hosted App from command line
I have a Blazor hosted application with a client (webassembly), server and shared project (from the webassembly hosted template).我有一个 Blazor 托管应用程序,其中包含一个客户端(webassembly)、服务器和共享项目(来自 webassembly 托管模板)。 It runs fine from Visual Studio, but I don't know how to run it from the command line.
它在 Visual Studio 中运行良好,但我不知道如何从命令行运行它。 I've tried:
我试过了:
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.
我想将它推送到 Cloud Foundry,但不能不知道如何运行它。
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:托管 Blazor 应用程序(即具有 Blazor 客户端部分和服务器 Web API 部分的应用程序)在 Windows 命令提示符中以这种方式创建:
md NameOfYourApp
cd NameOfYourApp
dotnet new blazorwasm --hosted
This creates a Blazor app with Client, Server, and Shared folders under NameOfYourApp.这将创建一个 Blazor 应用程序,其中包含 NameOfYourApp 下的 Client、Server 和 Shared 文件夹。
Using dotnet run
within the Client or Server folders won't work properly.在客户端或服务器文件夹中使用
dotnet run
将无法正常工作。 Instead, to run your app from the command line, run the Server .exe file created when you build:相反,要从命令行运行您的应用程序,请运行构建时创建的 Server .exe 文件:
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.) (如果不切换到 .exe 所在的目录,您的应用将无法找到 appsettings.json 文件。)
On .NET 5, I was able to get my Blazor Client-Side App to run by using dotnet run
在 .NET 5 上,我能够使用
dotnet run
来运行我的 Blazor 客户端应用程序
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.它应该显示类似
Now listening on https://localhost:5001
,您应该能够在浏览器中导航到那里。
If that doesn't work, you may need to configure your SSL cert.如果这不起作用,您可能需要配置您的 SSL 证书。 I had to add this
"Key"
section to my appsettings.json
.我必须将此
"Key"
部分添加到我的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
查看您的证书
ls Cert:\CurrentUser\My\{thumbprint}
Just use tab completion to figure out the path只需使用制表符完成来找出路径
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.