Tooling for ASP.NET Core Blazor
This article describes tools for building Blazor apps on various platforms.
Install the latest version of Visual Studio 2022 with the ASP.NET and web development workload.
Create a new project.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template. For a Blazor Server experience, choose the Blazor Server App template. Select Next.
Provide a Project name and confirm that the Location is correct. Select Next.
In the Additional information dialog, select the ASP.NET Core hosted checkbox for a hosted Blazor WebAssembly app. Select Create.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
When running a hosted Blazor WebAssembly solution in Visual Studio, the startup project of the solution is the
Serverproject.
For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Use the .NET command-line interface (CLI) to execute commands in a Linux command shell.
Install the latest version of the .NET Core SDK. If you previously installed the SDK, you can determine your installed version by executing the following command:
dotnet --versionInstall the latest version of Visual Studio Code.
Install the latest C# for Visual Studio Code extension.
For a Blazor WebAssembly experience, execute the following command:
dotnet new blazorwasm -o WebApplication1For a hosted Blazor WebAssembly experience, add the hosted option (
-hoor--hosted) option to the command:dotnet new blazorwasm -o WebApplication1 -hoFor a Blazor Server experience, execute the following command:
dotnet new blazorserver -o WebApplication1For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Open the
WebApplication1folder in Visual Studio Code.The IDE requests that you add assets to build and debug the project. Select Yes.
If Visual Studio Code doesn't offer to create the assets automatically, use the following files:
.vscode/launch.json(configured for launch and debug of a Blazor WebAssembly app):{ "version": "0.2.0", "configurations": [ { "type": "blazorwasm", "name": "Launch and Debug Blazor WebAssembly Application", "request": "launch", "cwd": "${workspaceFolder}", "browser": "edge" } ] }.vscode/tasks.json:{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "shell", "args": [ "build", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", ], "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }The project's
Properties/launchSettings.jsonfile includes theinspectUriproperty for the debugging proxy for any profiles in theprofilessection of the file:"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",Hosted Blazor WebAssembly launch and task configuration
For hosted Blazor WebAssembly solutions, add (or move) the
.vscodefolder withlaunch.jsonandtasks.jsonfiles to the solution's parent folder, which is the folder that contains the typical project folders:Client,Server, andShared. Update or confirm that the configuration in thelaunch.jsonandtasks.jsonfiles execute a hosted Blazor WebAssembly app from theServerproject.Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's
Serverproject.Examine the
Properties/launchSettings.jsonfile and determine the URL of the app from theapplicationUrlproperty (for example,https://localhost:7268). Note this value for use in thelaunch.jsonfile.In the launch configuration of the
.vscode/launch.jsonfile:- Set the current working directory (
cwd) to theServerproject folder. - Indicate the app's URL with the
urlproperty. Use the value recorded earlier from theProperties/launchSettings.jsonfile.
"cwd": "${workspaceFolder}/{SERVER APP FOLDER}", "url": "{URL}"In the preceding configuration:
- The
{SERVER APP FOLDER}placeholder is theServerproject's folder, typicallyServer. - The
{URL}placeholder is the app's URL, which is specified in the app'sProperties/launchSettings.jsonfile in theapplicationUrlproperty.
If Microsoft Edge is used and Google Chrome isn't installed on the system, add an additional property of
"browser": "edge"to the configuration.The following example
.vscode/launch.jsonfile:- Sets the current working directory to the
Serverfolder. - Sets the URL for the app to
https://localhost:7268. - Changes the default browser from Google Chrome to Microsoft Edge.
"cwd": "${workspaceFolder}/Server", "url": "https://localhost:7268", "browser": "edge"The complete
.vscode/launch.jsonfile:{ "version": "0.2.0", "configurations": [ { "type": "blazorwasm", "name": "Launch and Debug Blazor WebAssembly Application", "request": "launch", "cwd": "${workspaceFolder}/Server", "url": "https://localhost:7268", "browser": "edge" } ] }In
.vscode/tasks.json, add abuildargument that specifies the path to theServerapp's project file:"${workspaceFolder}/{SERVER APP FOLDER}/{PROJECT NAME}.csproj",In the preceding argument:
- The
{SERVER APP FOLDER}placeholder is theServerproject's folder, typicallyServer. - The
{PROJECT NAME}placeholder is the app's name, typically based on the solution's name followed by.Serverin an app generated from the Blazor WebAssembly project template.
An example
.vscode/tasks.jsonfile with aServerproject namedBlazorHostedin theServerfolder of the solution:{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Server/BlazorHosted.Server.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", ], "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }- Set the current working directory (
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
Note
Only browser debugging is supported at this time.
You can't automatically rebuild the backend Server app of a hosted Blazor WebAssembly solution during debugging, for example by running the app with dotnet watch run.
Trust a development certificate
For more information, see Enforce HTTPS in ASP.NET Core.
Install Visual Studio for Mac. When the installer requests the workloads to install, select .NET.
Select New Project from the File menu or create a New project from the Start Window.
In the sidebar, select Web and Console > App.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template. For a Blazor Server experience, choose the Blazor Server App template. Select Continue.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Confirm that Authentication is set to No Authentication. Select Continue.
For a hosted Blazor WebAssembly experience, select the ASP.NET Core hosted checkbox.
In the Project name field, name the app
WebApplication1. Select Create.Select the Start Without Debugging command from the Debug menu to run the app without the debugger. Run the app with Debug > Start Debugging or the Run (▶) button to run the app with the debugger.
If a prompt appears to trust the development certificate, trust the certificate and continue. The user and keychain passwords are required to trust the certificate. For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Visual Studio solution file (.sln)
A solution is a container to organize one or more related code projects. Visual Studio and Visual Studio for Mac use a solution file (.sln) to store settings for a solution. Solution files use a unique format and aren't intended to be edited directly.
Tooling outside of Visual Studio and Visual Studio for Mac can interact with solution files:
- The .NET CLI can create solution files and list/modify the projects in solution files via the
dotnet slncommand. Other .NET CLI commands use the path of the solution file for various publishing, testing, and packaging commands. - Visual Studio Code can execute the
dotnet slncommand and other .NET CLI commands through its integrated terminal but doesn't use the settings in a solution file directly.
Throughout the Blazor documentation, solution is used to describe apps created from the Blazor WebAssembly project template with the ASP.NET Core hosted option enabled or from a Blazor Hybrid project template. Apps produced from these project templates include a solution file (.sln) by default. For hosted Blazor WebAssembly apps where the developer isn't using Visual Studio or Visual Studio for Mac, the solution file can be ignored or deleted if it isn't used with .NET CLI commands.
For more information, see the following resources in the Visual Studio documentation:
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Blazor template options
The Blazor framework provides templates for creating new apps for each of the two Blazor hosting models. The templates are used to create new Blazor projects and solutions regardless of the tooling that you select for Blazor development (Visual Studio, Visual Studio for Mac, Visual Studio Code, or the .NET command-line interface (CLI)):
- Blazor Server project template:
blazorserver - Blazor WebAssembly project template:
blazorwasm
For more information on Blazor's hosting models, see ASP.NET Core Blazor hosting models. For more information on Blazor project templates, see ASP.NET Core Blazor project structure.
For more information on template options, see the following resources:
- .NET default templates for dotnet new article in the .NET Core documentation:
- Passing the help option (
-hor--help) to thedotnet newCLI command in a command shell:dotnet new blazorserver -hdotnet new blazorwasm -h
.NET WebAssembly build tools
The .NET WebAssembly build tools are based on Emscripten, a compiler toolchain for the web platform. To install the .NET WebAssembly build tools, use either of the following approaches:
- For the ASP.NET and web development workload in the Visual Studio installer, select the .NET WebAssembly build tools option from the list of optional components.
- Run
dotnet workload install wasm-toolsin a command shell.
For more information, see the following resources:
- Ahead-of-time (AOT) compilation
- Runtime relinking
- ASP.NET Core Blazor WebAssembly native dependencies
Additional resources
Install the latest version of Visual Studio 2022 with the ASP.NET and web development workload.
Create a new project.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template. For a Blazor Server experience, choose the Blazor Server App template. Select Next.
Provide a Project name and confirm that the Location is correct. Select Next.
In the Additional information dialog, select the ASP.NET Core hosted checkbox for a hosted Blazor WebAssembly app. Select Create.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
When running a hosted Blazor WebAssembly solution in Visual Studio, the startup project of the solution is the
Serverproject.
For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Install the latest version of the .NET Core SDK. If you previously installed the SDK, you can determine your installed version by executing the following command in a command shell:
dotnet --versionInstall the latest version of Visual Studio Code.
Install the latest C# for Visual Studio Code extension.
For a Blazor WebAssembly experience, execute the following command in a command shell:
dotnet new blazorwasm -o WebApplication1For a hosted Blazor WebAssembly experience, add the hosted option (
-hoor--hosted) option to the command:dotnet new blazorwasm -o WebApplication1 -hoFor a Blazor Server experience, execute the following command in a command shell:
dotnet new blazorserver -o WebApplication1For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Open the
WebApplication1folder in Visual Studio Code.The IDE requests that you add assets to build and debug the project. Select Yes.
If Visual Studio Code doesn't offer to create the assets automatically, use the following files:
.vscode/launch.json(configured for launch and debug of a Blazor WebAssembly app):{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "blazorwasm", "name": "Launch and Debug Blazor WebAssembly Application", "request": "launch", "cwd": "${workspaceFolder}", "browser": "edge" } ] }.vscode/tasks.json:{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "shell", "args": [ "build", // Ask dotnet build to generate full paths for file names. "/property:GenerateFullPaths=true", // Do not generate summary otherwise it leads to duplicate errors in Problems panel "/consoleloggerparameters:NoSummary", ], "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }Hosted Blazor WebAssembly launch and task configuration
For hosted Blazor WebAssembly solutions, add (or move) the
.vscodefolder withlaunch.jsonandtasks.jsonfiles to the solution's parent folder, which is the folder that contains the typical project folders:Client,Server, andShared. Update or confirm that the configuration in thelaunch.jsonandtasks.jsonfiles execute a hosted Blazor WebAssembly app from theServerproject.Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's
Serverproject..vscode/launch.json(launchconfiguration):... "cwd": "${workspaceFolder}/{SERVER APP FOLDER}", ...In the preceding configuration for the current working directory (
cwd), the{SERVER APP FOLDER}placeholder is theServerproject's folder, typically "Server".If Microsoft Edge is used and Google Chrome isn't installed on the system, add an additional property of
"browser": "edge"to the configuration.Example for a project folder of
Serverand that spawns Microsoft Edge as the browser for debug runs instead of the default browser Google Chrome:... "cwd": "${workspaceFolder}/Server", "browser": "edge" ....vscode/tasks.json(dotnetcommand arguments):... "${workspaceFolder}/{SERVER APP FOLDER}/{PROJECT NAME}.csproj", ...In the preceding argument:
- The
{SERVER APP FOLDER}placeholder is theServerproject's folder, typically "Server". - The
{PROJECT NAME}placeholder is the app's name, typically based on the solution's name followed by ".Server" in an app generated from the Blazor project template.
The following example from the tutorial for using SignalR with a Blazor WebAssembly app uses a project folder name of
Serverand a project name ofBlazorWebAssemblySignalRApp.Server:... "args": [ "build", "${workspaceFolder}/Server/BlazorWebAssemblySignalRApp.Server.csproj", ... ], ...- The
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
Trust a development certificate
For more information, see Enforce HTTPS in ASP.NET Core.
Install Visual Studio for Mac. When the installer requests the workloads to install, select .NET.
Select New Project from the File menu or create a New project from the Start Window.
In the sidebar, select Web and Console > App.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template. For a Blazor Server experience, choose the Blazor Server App template. Select Continue.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Confirm that Authentication is set to No Authentication. Select Continue.
For a hosted Blazor WebAssembly experience, select the ASP.NET Core hosted checkbox.
In the Project name field, name the app
WebApplication1. Select Create.Select the Start Without Debugging command from the Debug menu to run the app without the debugger. Run the app with Debug > Start Debugging or the Run (▶) button to run the app with the debugger.
If a prompt appears to trust the development certificate, trust the certificate and continue. The user and keychain passwords are required to trust the certificate. For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Visual Studio solution file (.sln)
A solution is a container to organize one or more related code projects. Visual Studio and Visual Studio for Mac use a solution file (.sln) to store settings for a solution. Solution files use a unique format and aren't intended to be edited directly.
Tooling outside of Visual Studio and Visual Studio for Mac can interact with solution files:
- The .NET CLI can create solution files and list/modify the projects in solution files via the
dotnet slncommand. Other .NET CLI commands use the path of the solution file for various publishing, testing, and packaging commands. - Visual Studio Code can execute the
dotnet slncommand and other .NET CLI commands through its integrated terminal but doesn't use the settings in a solution file directly.
Throughout the Blazor documentation, solution is used to describe apps created from the Blazor WebAssembly project template with the ASP.NET Core hosted option enabled or from a Blazor Hybrid project template. Apps produced from these project templates include a solution file (.sln) by default. For hosted Blazor WebAssembly apps where the developer isn't using Visual Studio or Visual Studio for Mac, the solution file can be ignored or deleted if it isn't used with .NET CLI commands.
For more information, see the following resources in the Visual Studio documentation:
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Blazor template options
The Blazor framework provides templates for creating new apps for each of the two Blazor hosting models. The templates are used to create new Blazor projects and solutions regardless of the tooling that you select for Blazor development (Visual Studio, Visual Studio for Mac, Visual Studio Code, or the .NET CLI):
- Blazor WebAssembly project template:
blazorwasm - Blazor Server project template:
blazorserver
For more information on Blazor's hosting models, see ASP.NET Core Blazor hosting models. For more information on Blazor project templates, see ASP.NET Core Blazor project structure.
Template options are available by passing the help option (-h or --help) to the dotnet new CLI command in a command shell:
dotnet new blazorwasm -h
dotnet new blazorserver -h
Additional resources
Install the latest version of Visual Studio 2022 with the ASP.NET and web development workload.
Create a new project.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template. For a Blazor Server experience, choose the Blazor Server App template. Select Next.
Provide a Project name and confirm that the Location is correct. Select Next.
In the Additional information dialog, select the ASP.NET Core hosted checkbox for a hosted Blazor WebAssembly app. Select Create.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
When running a hosted Blazor WebAssembly solution in Visual Studio, the startup project of the solution is the
Serverproject.
For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Install the latest version of the .NET Core SDK. If you previously installed the SDK, you can determine your installed version by executing the following command in a command shell:
dotnet --versionInstall the latest version of Visual Studio Code.
Install the latest C# for Visual Studio Code extension.
For a Blazor WebAssembly experience, execute the following command in a command shell:
dotnet new blazorwasm -o WebApplication1For a hosted Blazor WebAssembly experience, add the hosted option (
-hoor--hosted) option to the command:dotnet new blazorwasm -o WebApplication1 -hoFor a Blazor Server experience, execute the following command in a command shell:
dotnet new blazorserver -o WebApplication1For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Open the
WebApplication1folder in Visual Studio Code.The IDE requests that you add assets to build and debug the project. Select Yes.
If Visual Studio Code doesn't offer to create the assets automatically, use the following files:
.vscode/launch.json(configured for launch and debug of a Blazor WebAssembly app):{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "blazorwasm", "name": "Launch and Debug Blazor WebAssembly Application", "request": "launch", "cwd": "${workspaceFolder}", "browser": "edge" } ] }.vscode/tasks.json:{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "shell", "args": [ "build", // Ask dotnet build to generate full paths for file names. "/property:GenerateFullPaths=true", // Do not generate summary otherwise it leads to duplicate errors in Problems panel "/consoleloggerparameters:NoSummary", ], "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }Hosted Blazor WebAssembly launch and task configuration
For hosted Blazor WebAssembly solutions, add (or move) the
.vscodefolder withlaunch.jsonandtasks.jsonfiles to the solution's parent folder, which is the folder that contains the typical project folders:Client,Server, andShared. Update or confirm that the configuration in thelaunch.jsonandtasks.jsonfiles execute a hosted Blazor WebAssembly app from theServerproject..vscode/launch.json(launchconfiguration):... "cwd": "${workspaceFolder}/{SERVER APP FOLDER}", ...In the preceding configuration for the current working directory (
cwd), the{SERVER APP FOLDER}placeholder is theServerproject's folder, typically "Server".If Microsoft Edge is used and Google Chrome isn't installed on the system, add an additional property of
"browser": "edge"to the configuration.Example for a project folder of
Serverand that spawns Microsoft Edge as the browser for debug runs instead of the default browser Google Chrome:... "cwd": "${workspaceFolder}/Server", "browser": "edge" ....vscode/tasks.json(dotnetcommand arguments):... "${workspaceFolder}/{SERVER APP FOLDER}/{PROJECT NAME}.csproj", ...In the preceding argument:
- The
{SERVER APP FOLDER}placeholder is theServerproject's folder, typically "Server". - The
{PROJECT NAME}placeholder is the app's name, typically based on the solution's name followed by ".Server" in an app generated from the Blazor project template.
The following example from the tutorial for using SignalR with a Blazor WebAssembly app uses a project folder name of
Serverand a project name ofBlazorWebAssemblySignalRApp.Server:... "args": [ "build", "${workspaceFolder}/Server/BlazorWebAssemblySignalRApp.Server.csproj", ... ], ...- The
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
Trust a development certificate
For more information, see Enforce HTTPS in ASP.NET Core.
Install Visual Studio for Mac. When the installer requests the workloads to install, select .NET.
Select New Project from the File menu or create a New project from the Start Window.
In the sidebar, select Web and Console > App.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template. For a Blazor Server experience, choose the Blazor Server App template. Select Continue.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Confirm that Authentication is set to No Authentication. Select Continue.
For a hosted Blazor WebAssembly experience, select the ASP.NET Core hosted checkbox.
In the Project name field, name the app
WebApplication1. Select Create.Select the Start Without Debugging command from the Debug menu to run the app without the debugger. Run the app with Debug > Start Debugging or the Run (▶) button to run the app with the debugger.
If a prompt appears to trust the development certificate, trust the certificate and continue. The user and keychain passwords are required to trust the certificate. For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Visual Studio solution file (.sln)
A solution is a container to organize one or more related code projects. Visual Studio and Visual Studio for Mac use a solution file (.sln) to store settings for a solution. Solution files use a unique format and aren't intended to be edited directly.
Tooling outside of Visual Studio and Visual Studio for Mac can interact with solution files:
- The .NET CLI can create solution files and list/modify the projects in solution files via the
dotnet slncommand. Other .NET CLI commands use the path of the solution file for various publishing, testing, and packaging commands. - Visual Studio Code can execute the
dotnet slncommand and other .NET CLI commands through its integrated terminal but doesn't use the settings in a solution file directly.
Throughout the Blazor documentation, solution is used to describe apps created from the Blazor WebAssembly project template with the ASP.NET Core hosted option enabled or from a Blazor Hybrid project template. Apps produced from these project templates include a solution file (.sln) by default. For hosted Blazor WebAssembly apps where the developer isn't using Visual Studio or Visual Studio for Mac, the solution file can be ignored or deleted if it isn't used with .NET CLI commands.
For more information, see the following resources in the Visual Studio documentation:
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Blazor template options
The Blazor framework provides templates for creating new apps for each of the two Blazor hosting models. The templates are used to create new Blazor projects and solutions regardless of the tooling that you select for Blazor development (Visual Studio, Visual Studio for Mac, Visual Studio Code, or the .NET CLI):
- Blazor WebAssembly project template:
blazorwasm - Blazor Server project template:
blazorserver
For more information on Blazor's hosting models, see ASP.NET Core Blazor hosting models. For more information on Blazor project templates, see ASP.NET Core Blazor project structure.
Template options are available by passing the help option (-h or --help) to the dotnet new CLI command in a command shell:
dotnet new blazorwasm -h
dotnet new blazorserver -h
Additional resources
Install the latest version of Visual Studio 2022 with the ASP.NET and web development workload.
Create a new project.
For a Blazor Server experience, choose the Blazor Server App template, which includes demonstration code and Bootstrap, or the Blazor Server App Empty template without demonstration code and Bootstrap. Select Next.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template, which includes demonstration code and Bootstrap, or the Blazor WebAssembly App Empty template without demonstration code and Bootstrap.
Provide a Project name and confirm that the Location is correct. Select Next.
In the Additional information dialog, select the ASP.NET Core hosted checkbox for a hosted Blazor WebAssembly app. Select Create.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
When running a hosted Blazor WebAssembly solution in Visual Studio, the startup project of the solution is the
Serverproject.
For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Use the .NET command-line interface (CLI) to execute commands in a Linux command shell.
Install the latest version of the .NET Core SDK. If you previously installed the SDK, you can determine your installed version by executing the following command:
dotnet --versionInstall the latest version of Visual Studio Code.
Install the latest C# for Visual Studio Code extension.
For a Blazor Server experience with demonstration code and Bootstrap, execute the following command:
dotnet new blazorserver -o WebApplication1Alternatively, create an app without demonstration code and Bootstrap using the
blazorserver-emptyproject template:dotnet new blazorserver-empty -o WebApplication1For a Blazor WebAssembly experience with demonstration code and Bootstrap, execute the following command:
dotnet new blazorwasm -o WebApplication1Alternatively, create an app without demonstration code and Bootstrap using the
blazorwasm-emptyproject template:dotnet new blazorwasm-empty -o WebApplication1For a hosted Blazor WebAssembly experience with demonstration code and Bootstrap, add the hosted option (
-ho/--hosted) to the command:dotnet new blazorwasm -o WebApplication1 -hoAlternatively, create a hosted Blazor WebAssembly app without demonstration code and Bootstrap using the
blazorwasm-emptytemplate with the hosted option:dotnet new blazorwasm-empty -o WebApplication1 -hoFor information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Open the
WebApplication1folder in Visual Studio Code.The IDE requests that you add assets to build and debug the project. Select Yes.
If Visual Studio Code doesn't offer to create the assets automatically, use the following files:
.vscode/launch.json(configured for launch and debug of a Blazor WebAssembly app):{ "version": "0.2.0", "configurations": [ { "type": "blazorwasm", "name": "Launch and Debug Blazor WebAssembly Application", "request": "launch", "cwd": "${workspaceFolder}", "browser": "edge" } ] }.vscode/tasks.json:{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "shell", "args": [ "build", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", ], "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }The project's
Properties/launchSettings.jsonfile includes theinspectUriproperty for the debugging proxy for any profiles in theprofilessection of the file:"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}",Hosted Blazor WebAssembly launch and task configuration
For hosted Blazor WebAssembly solutions, add (or move) the
.vscodefolder withlaunch.jsonandtasks.jsonfiles to the solution's parent folder, which is the folder that contains the typical project folders:Client,Server, andShared. Update or confirm that the configuration in thelaunch.jsonandtasks.jsonfiles execute a hosted Blazor WebAssembly app from theServerproject.Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's
Serverproject.Examine the
Properties/launchSettings.jsonfile and determine the URL of the app from theapplicationUrlproperty (for example,https://localhost:7268). Note this value for use in thelaunch.jsonfile.In the launch configuration of the
.vscode/launch.jsonfile:- Set the current working directory (
cwd) to theServerproject folder. - Indicate the app's URL with the
urlproperty. Use the value recorded earlier from theProperties/launchSettings.jsonfile.
"cwd": "${workspaceFolder}/{SERVER APP FOLDER}", "url": "{URL}"In the preceding configuration:
- The
{SERVER APP FOLDER}placeholder is theServerproject's folder, typicallyServer. - The
{URL}placeholder is the app's URL, which is specified in the app'sProperties/launchSettings.jsonfile in theapplicationUrlproperty.
If Google Chrome is preferred over Microsoft Edge, update or add an additional property of
"browser": "chrome"to the configuration.The following example
.vscode/launch.jsonfile:- Sets the current working directory to the
Serverfolder. - Sets the URL for the app to
https://localhost:7268. - Changes the default browser from Microsoft Edge to Google Chrome.
"cwd": "${workspaceFolder}/Server", "url": "https://localhost:7268", "browser": "chrome"The complete
.vscode/launch.jsonfile:{ "version": "0.2.0", "configurations": [ { "type": "blazorwasm", "name": "Launch and Debug Blazor WebAssembly Application", "request": "launch", "cwd": "${workspaceFolder}/Server", "url": "https://localhost:7268", "browser": "chrome" } ] }In
.vscode/tasks.json, add abuildargument that specifies the path to theServerapp's project file:"${workspaceFolder}/{SERVER APP FOLDER}/{PROJECT NAME}.csproj",In the preceding argument:
- The
{SERVER APP FOLDER}placeholder is theServerproject's folder, typicallyServer. - The
{PROJECT NAME}placeholder is the app's name, typically based on the solution's name followed by.Serverin an app generated from the Blazor WebAssembly project template.
An example
.vscode/tasks.jsonfile with aServerproject namedBlazorHostedin theServerfolder of the solution:{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Server/BlazorHosted.Server.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary", ], "group": "build", "presentation": { "reveal": "silent" }, "problemMatcher": "$msCompile" } ] }- Set the current working directory (
Press Ctrl+F5 (Windows) or ⌘+F5 (macOS) to run the app.
Note
Only browser debugging is supported at this time.
You can't automatically rebuild the backend Server app of a hosted Blazor WebAssembly solution during debugging, for example by running the app with dotnet watch run.
Trust a development certificate
For more information, see Enforce HTTPS in ASP.NET Core.
Install Visual Studio for Mac. When the installer requests the workloads to install, select .NET.
Select New Project from the File menu or create a New project from the Start Window.
In the sidebar, select Web and Console > App.
For a Blazor Server experience, choose the Blazor Server App template, which includes demonstration code and Bootstrap, or the Blazor Server App Empty template without demonstration code and Bootstrap. Select Continue.
For a Blazor WebAssembly experience, choose the Blazor WebAssembly App template, which includes demonstration code and Bootstrap, or the Blazor WebAssembly App Empty template without demonstration code and Bootstrap.
For information on the two Blazor hosting models, Blazor WebAssembly (standalone and hosted) and Blazor Server, see ASP.NET Core Blazor hosting models.
Confirm that Authentication is set to No Authentication. Select Continue.
For a hosted Blazor WebAssembly experience, select the ASP.NET Core hosted checkbox.
In the Project name field, name the app
WebApplication1. Select Create.Select the Start Without Debugging command from the Debug menu to run the app without the debugger. Run the app with Debug > Start Debugging or the Run (▶) button to run the app with the debugger.
If a prompt appears to trust the development certificate, trust the certificate and continue. The user and keychain passwords are required to trust the certificate. For more information on trusting the ASP.NET Core HTTPS development certificate, see Enforce HTTPS in ASP.NET Core.
Important
When executing a hosted Blazor WebAssembly app, run the app from the solution's Server project.
Visual Studio solution file (.sln)
A solution is a container to organize one or more related code projects. Visual Studio and Visual Studio for Mac use a solution file (.sln) to store settings for a solution. Solution files use a unique format and aren't intended to be edited directly.
Tooling outside of Visual Studio and Visual Studio for Mac can interact with solution files:
- The .NET CLI can create solution files and list/modify the projects in solution files via the
dotnet slncommand. Other .NET CLI commands use the path of the solution file for various publishing, testing, and packaging commands. - Visual Studio Code can execute the
dotnet slncommand and other .NET CLI commands through its integrated terminal but doesn't use the settings in a solution file directly.
Throughout the Blazor documentation, solution is used to describe apps created from the Blazor WebAssembly project template with the ASP.NET Core hosted option enabled or from a Blazor Hybrid project template. Apps produced from these project templates include a solution file (.sln) by default. For hosted Blazor WebAssembly apps where the developer isn't using Visual Studio or Visual Studio for Mac, the solution file can be ignored or deleted if it isn't used with .NET CLI commands.
For more information, see the following resources in the Visual Studio documentation:
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Use Visual Studio Code for cross-platform Blazor development
Visual Studio Code is an open source, cross-platform Integrated Development Environment (IDE) that can be used to develop Blazor apps. Use the .NET CLI to create a new Blazor app for development with Visual Studio Code. For more information, see the Linux version of this article.
Blazor template options
The Blazor framework provides templates for creating new apps for each of the two Blazor hosting models. The templates are used to create new Blazor projects and solutions regardless of the tooling that you select for Blazor development (Visual Studio, Visual Studio for Mac, Visual Studio Code, or the .NET command-line interface (CLI)):
- Blazor Server project templates:
blazorserver,blazorserver-empty - Blazor WebAssembly project templates:
blazorwasm,blazorwasm-empty
For more information on Blazor's hosting models, see ASP.NET Core Blazor hosting models. For more information on Blazor project templates, see ASP.NET Core Blazor project structure.
For more information on template options, see the following resources:
- .NET default templates for dotnet new article in the .NET Core documentation:
- Passing the help option (
-hor--help) to thedotnet newCLI command in a command shell:dotnet new blazorserver -hdotnet new blazorwasm -h
.NET WebAssembly build tools
The .NET WebAssembly build tools are based on Emscripten, a compiler toolchain for the web platform. To install the .NET WebAssembly build tools, use either of the following approaches:
- For the ASP.NET and web development workload in the Visual Studio installer, select the .NET WebAssembly build tools option from the list of optional components.
- Run
dotnet workload install wasm-toolsin a command shell.
For more information, see the following resources:
- Ahead-of-time (AOT) compilation
- Runtime relinking
- ASP.NET Core Blazor WebAssembly native dependencies
Additional resources
Povratne informacije
Pošalјite i prikažite povratne informacije za