You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add AddServerComponents() to Blazor Web App project template #48952
Is your feature request related to a problem? Please describe the problem.
No response
Describe the solution you'd like
I have been using blazor for some years, but now I tried the new Blazor Web App project template and noticed that a very important call is missing: services.AddRazorComponents().AddServerComponents()
I think that this should be included, or at least commented, in the project template:
Hi, @javiercn ! I checked again now and used both dotnet new command and Microsoft Visual Studio Community 2022 (64-bit) - Preview (Version 17.7.0 Preview 2.0)
and got this same template that does not even mention the .AddServerComponents()
dotnet --list-sdks
6.0.100-preview.7.21379.14 [C:\Program Files\dotnet\sdk]
6.0.410 [C:\Program Files\dotnet\sdk]
7.0.400-preview.23274.1 [C:\Program Files\dotnet\sdk]
8.0.100-preview.5.23303.2 [C:\Program Files\dotnet\sdk]
dotnet new blazor
O modelo "Blazor Web App" foi criado com êxito.
Este modelo contém tecnologias de outras pessoas além da Microsoft, consulte https://aka.ms/aspnetcore/8.0-third-party-notices para obter detalhes.
Processando ações pós-criação...
Restaurando C:\temp\blazor_net8\blazor_net8.csproj:
Determinando os projetos a serem restaurados...
C:\temp\blazor_net8\blazor_net8.csproj restaurado (em 154 ms).
A restauração foi bem-sucedida.
Program.cs
using BlazorApp3;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapRazorComponents<App>();
app.Run();
I think that the whole idea is converging to have a single Blazor project template that works seamlessy on server, webassembly and now also has the SSR (kind of static behaviour like a classic ASP.NET of PHP page), wich is very cool.
Why not include the call that makes Blazor interactivity work out of the box and to not require the coder to create another project with some option to have this included?
For example, I am used to create a new blazor project, hit the Visual Studio play button and the interactivity works. Now when trying the new template, I got surprised that I ran the new project and the interactivity did not work, so I had to manually search for and add that call AddServerComponents().
That is why I suggested that at least it came commented on the template code.
@TonyHenrique but it's going to show up in the final version of the template, and it's likely going to be checked by default, so you'll have to remove it to be in that situation.
Activity
javiercn commentedon Jun 22, 2023
@TonyHenrique thanks for contacting us.
That gets automatically included when the server option is selected as part of the template creation.
TonyHenrique commentedon Jun 22, 2023
Hi, @javiercn ! I checked again now and used both
dotnet newcommand and Microsoft Visual Studio Community 2022 (64-bit) - Preview (Version 17.7.0 Preview 2.0)and got this same template that does not even mention the
.AddServerComponents()Program.cs
javiercn commentedon Jun 22, 2023
@TonyHenrique we have yet to surface the server option on the template.
It's there, just hidden. It'll be visible in preview6.
TonyHenrique commentedon Jun 22, 2023
Got it.
Then, please consider this to be included, or at least commented, in the project template:
javiercn commentedon Jun 22, 2023
@TonyHenrique why is it not enough with the option in the template?
TonyHenrique commentedon Jun 22, 2023
I think that the whole idea is converging to have a single Blazor project template that works seamlessy on server, webassembly and now also has the SSR (kind of static behaviour like a classic ASP.NET of PHP page), wich is very cool.
Why not include the call that makes Blazor interactivity work out of the box and to not require the coder to create another project with some option to have this included?
For example, I am used to create a new blazor project, hit the Visual Studio play button and the interactivity works. Now when trying the new template, I got surprised that I ran the new project and the interactivity did not work, so I had to manually search for and add that call
AddServerComponents().That is why I suggested that at least it came commented on the template code.
javiercn commentedon Jun 22, 2023
@TonyHenrique but it's going to show up in the final version of the template, and it's likely going to be checked by default, so you'll have to remove it to be in that situation.