Aspnetcore: Blazor: Default template doesn't run on newest version

Created on 20 Apr 2019  路  17Comments  路  Source: dotnet/aspnetcore

Describe the bug

When I create a new blazor project using the most recent version it builds but it doesn't run.

To Reproduce

  1. Install .NET Core SDK (3.0.100-preview4-011223)
  2. dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview4-19216-03
  3. dotnet new blazor
  4. dotnet build
  5. dotnet run

Error Message

> dotnet run
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-C:\Users\Ricardo does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

Additional context

> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.0.100-preview4-011223
 Commit:    118dd862c8

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17763
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\

Host (useful for support):
  Version: 3.0.0-preview4-27615-11
  Commit:  ee54d4cbd2

.NET Core SDKs installed:
  2.1.504 [C:\Program Files\dotnet\sdk]
  2.1.602 [C:\Program Files\dotnet\sdk]
  2.2.105 [C:\Program Files\dotnet\sdk]
  3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0-preview4-19216-03 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0-preview4-27615-11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0-preview4-27613-28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Done area-blazor bug

All 17 comments

@rjmr97 Did you cd into the folder?

@rjmr97 Did you cd into the folder?

@davidfowl I don't think I need to cd after dotnet new because I didn't specify a folder
I tried it again, here's the full output:

D:\>mkdir test && cd test

D:\test>dotnet new blazor
The template "Blazor (client-side)" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on D:\test\test.csproj...
  Restore completed in 240.32 ms for D:\test\test.csproj.

Restore succeeded.


D:\test>dotnet build
Microsoft (R) Build Engine version 16.1.54-preview+gd004974104 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 26.34 ms for D:\test\test.csproj.
C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(151,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [D:\test\test.csproj]
  test -> D:\test\bin\Debug\netstandard2.0\test.dll
  Processing embedded resource linker descriptor: mscorlib.xml
  Duplicate preserve in resource mscorlib.xml in mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e of System.Threading.WasmRuntime (All).  Duplicate uses (All)
  Type System.Reflection.Assembly has no fields to preserve
  Type Mono.ValueTuple has no fields to preserve
  Output action:     Link assembly: test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
  Output action:     Save assembly: System.ComponentModel.Annotations, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  Output action:     Save assembly: Mono.WebAssembly.Interop, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:     Save assembly: Microsoft.JSInterop, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:     Save assembly: Microsoft.Extensions.DependencyInjection.Abstractions, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:     Save assembly: Microsoft.Extensions.DependencyInjection, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:     Save assembly: Microsoft.AspNetCore.Components.Browser, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:     Save assembly: Microsoft.AspNetCore.Components, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:     Save assembly: Microsoft.AspNetCore.Blazor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
  Output action:   Delete assembly: netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
  Output action:     Link assembly: mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
  Output action:     Link assembly: System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
  Output action:     Link assembly: Mono.Security, Version=2.0.5.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756
  Output action:   Delete assembly: System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
  Output action:   Delete assembly: System.Numerics, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Output action:     Link assembly: System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
  Output action:   Delete assembly: System.Data, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Output action:   Delete assembly: System.Drawing.Common, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51
  Output action:   Delete assembly: System.IO.Compression, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Output action:   Delete assembly: System.IO.Compression.FileSystem, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Output action:   Delete assembly: System.ComponentModel.Composition, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Output action:     Link assembly: System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  Output action:   Delete assembly: System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
  Output action:   Delete assembly: System.Transactions, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
  Output action:   Delete assembly: System.Web.Services, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
  Output action:   Delete assembly: System.Xml.Linq, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  Output action:   Delete assembly: System.ServiceModel.Internals, Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
  Writing boot data to: D:\test\obj\Debug\netstandard2.0\blazor\blazor.boot.json
  Blazor Build result -> 20 files in D:\test\bin\Debug\netstandard2.0\dist

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:08.28

D:\test>dotnet run
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET Core program, but dotnet-C:\Users\Ricardo does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

D:\test>

I run into the same error message when running the commands from the Get started with Blazor documentation page:

dotnet new blazor -o WebApplication1
cd WebApplication1
dotnet run

Outputs the same message as @rjmr97, same dotnet --info.

@rjmr97 @jdebarochez Are you able to successfully run a console app using .NET Core 3.0?:

dotnet new console -o ConsoleApp1
cd ConsoleApp1
dotnet run

No problem with that:

PS C:\dev\draft\todelete> dotnet new console -o ConsoleApp1
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on ConsoleApp1\ConsoleApp1.csproj...
  Restore completed in 278.11 ms for C:\dev\draft\todelete\ConsoleApp1\ConsoleApp1.csproj.

Restore succeeded.

PS C:\dev\draft\todelete> cd ConsoleApp1
PS C:\dev\draft\todelete\ConsoleApp1> dotnet run
Hello World!

Only blazor template fails to run apparently. dotnet new blazorserver -o blazor-serverside works for me.

I can also run the console app with no problems.

D:\>mkdir test && cd test

D:\test>dotnet new console
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on D:\test\test.csproj...
  Restore completed in 126.13 ms for D:\test\test.csproj.

Restore succeeded.


D:\test>dotnet run
Hello World!

To add to @jdebarochez's response, I can run a blazorhosted app

D:\>mkdir test && cd test

D:\test>dotnet new blazorhosted
The template "Blazor (ASP.NET Core hosted)" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on D:\test\test.Server/test.Server.csproj...
  Restore completed in 240.35 ms for D:\test\test.Shared\test.Shared.csproj.
  Restore completed in 240.35 ms for D:\test\test.Client\test.Client.csproj.
  Restore completed in 668.47 ms for D:\test\test.Server\test.Server.csproj.

Restore succeeded.
Running 'dotnet restore' on D:\test\test.Client/test.Client.csproj...
  Restore completed in 27.01 ms for D:\test\test.Client\test.Client.csproj.
  Restore completed in 27.01 ms for D:\test\test.Shared\test.Shared.csproj.

Restore succeeded.
Running 'dotnet restore' on D:\test\test.Shared/test.Shared.csproj...
  Restore completed in 22.66 ms for D:\test\test.Shared\test.Shared.csproj.

Restore succeeded.


D:\test>cd test.Server

D:\test\test.Server>dotnet run
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\Ricardo Ribeiro\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Hosting environment: Production
Content root path: D:\test\test.Server
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

I think the problem may be Microsoft.AspNetCore.Blazor.DevServer since blazorhosted uses Microsoft.AspNetCore.Blazor.Server instead.

I'm having the exact issue with blazor (client-side) and I'm only able to create a blazorserver from Visual Studio but not from CLI.

Unable to determine the desired template from the input template name: blazorserver.
The following templates partially match the input. Be more specific with the template name and/or language.

Templates                                 Short Name            Language      Tags
---------------------------------------------------------------------------------------------------
Blazor (server-side)                      blazorserverside      [C#]          Web/Blazor
Blazor (Server-side in ASP.NET Core)      blazorserverside      [C#]          Web/Blazor/ServerSide

@ramimod Did you run the command dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview4-19216-03?

Whats your output of dotnet new --help?

@rjmr97

Output for
dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview4-19216-03

PS C:\Users\My User\Desktop\Blazor> dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview4-19216-03
  Restore completed in 454.36 ms for C:\Users\My User\.templateengine\dotnetcli\v3.0.100-preview4-011223\scratch\restore.csproj.

Usage: new [options]

Options:
  -h, --help          Displays help for this command.
  -l, --list          Lists templates containing the specified name. If no name is specified, lists all templates.
  -n, --name          The name for the output being created. If no name is specified, the name of the current directory is used.
  -o, --output        Location to place the generated output.
  -i, --install       Installs a source or a template pack.
  -u, --uninstall     Uninstalls a source or a template pack.
  --nuget-source      Specifies a NuGet source to use during install.
  --type              Filters templates based on available types. Predefined values are "project", "item" or "other".
  --dry-run           Displays a summary of what would happen if the given command line were run if it would result in a template creation.
  --force             Forces content to be generated even if it would change existing files.
  -lang, --language   Filters templates based on language and specifies the language of the template to create.


Templates                                         Short Name            Language          Tags                          
-------------------------------------------------------------------------------------------------------------------------------
Console Application                               console               [C#], F#, VB      Common/Console                
Class library                                     classlib              [C#], F#, VB      Common/Library                
WPF Application                                   wpf                   [C#]              Common/WPF                    
Windows Forms (WinForms) Application              winforms              [C#]              Common/WinForms               
Worker Service                                    worker                [C#]              Common/Worker/Web             
Unit Test Project                                 mstest                [C#], F#, VB      Test/MSTest                   
NUnit 3 Test Project                              nunit                 [C#], F#, VB      Test/NUnit                    
NUnit 3 Test Item                                 nunit-test            [C#], F#, VB      Test/NUnit                    
xUnit Test Project                                xunit                 [C#], F#, VB      Test/xUnit                    
Razor Component                                   razorcomponent        [C#]              Web/ASP.NET                   
Razor Page                                        page                  [C#]              Web/ASP.NET                   
MVC ViewImports                                   viewimports           [C#]              Web/ASP.NET                   
MVC ViewStart                                     viewstart             [C#]              Web/ASP.NET                   
Blazor (server-side)                              blazorserverside      [C#]              Web/Blazor                    
Blazor (ASP.NET Core hosted)                      blazorhosted          [C#]              Web/Blazor/Hosted             
Blazor Library                                    blazorlib             [C#]              Web/Blazor/Library            
Blazor (Server-side in ASP.NET Core)              blazorserverside      [C#]              Web/Blazor/ServerSide         
Blazor (client-side)                              blazor                [C#]              Web/Blazor/Standalone         
ASP.NET Core Empty                                web                   [C#], F#          Web/Empty                     
ASP.NET Core Web App (Model-View-Controller)      mvc                   [C#], F#          Web/MVC                       
ASP.NET Core Web App                              webapp                [C#]              Web/MVC/Razor Pages           
ASP.NET Core with Angular                         angular               [C#]              Web/MVC/SPA                   
ASP.NET Core with React.js                        react                 [C#]              Web/MVC/SPA                   
ASP.NET Core with React.js and Redux              reactredux            [C#]              Web/MVC/SPA                   
Razor Class Library                               razorclasslib         [C#]              Web/Razor/Library/Razor Class Library
ASP.NET Core Web API                              webapi                [C#], F#          Web/WebAPI                    
ASP.NET Core gRPC Service                         grpc                  [C#]              Web/gRPC                      
global.json file                                  globaljson                              Config                        
NuGet Config                                      nugetconfig                             Config                        
Dotnet local tool manifest file                   tool-manifest                           Config                        
Web Config                                        webconfig                               Config                        
Solution File                                     sln                                     Solution                      

Examples:
    dotnet new mvc --auth Individual
    dotnet new mstest
    dotnet new --help
PS C:\Users\My User\Desktop\Blazor>

Output for
dotnet new --help

PS C:\Users\My User\Desktop\Blazor> dotnet new --help
Usage: new [options]

Options:
  -h, --help          Displays help for this command.
  -l, --list          Lists templates containing the specified name. If no name is specified, lists all templates.
  -n, --name          The name for the output being created. If no name is specified, the name of the current directory is used.
  -o, --output        Location to place the generated output.
  -i, --install       Installs a source or a template pack.
  -u, --uninstall     Uninstalls a source or a template pack.
  --nuget-source      Specifies a NuGet source to use during install.
  --type              Filters templates based on available types. Predefined values are "project", "item" or "other".
  --dry-run           Displays a summary of what would happen if the given command line were run if it would result in a template creation.
  --force             Forces content to be generated even if it would change existing files.
  -lang, --language   Filters templates based on language and specifies the language of the template to create.


Templates                                         Short Name            Language          Tags                          
-------------------------------------------------------------------------------------------------------------------------------
Console Application                               console               [C#], F#, VB      Common/Console                
Class library                                     classlib              [C#], F#, VB      Common/Library                
WPF Application                                   wpf                   [C#]              Common/WPF                    
Windows Forms (WinForms) Application              winforms              [C#]              Common/WinForms               
Worker Service                                    worker                [C#]              Common/Worker/Web             
Unit Test Project                                 mstest                [C#], F#, VB      Test/MSTest                   
NUnit 3 Test Project                              nunit                 [C#], F#, VB      Test/NUnit                    
NUnit 3 Test Item                                 nunit-test            [C#], F#, VB      Test/NUnit                    
xUnit Test Project                                xunit                 [C#], F#, VB      Test/xUnit                    
Razor Component                                   razorcomponent        [C#]              Web/ASP.NET                   
Razor Page                                        page                  [C#]              Web/ASP.NET                   
MVC ViewImports                                   viewimports           [C#]              Web/ASP.NET                   
MVC ViewStart                                     viewstart             [C#]              Web/ASP.NET                   
Blazor (server-side)                              blazorserverside      [C#]              Web/Blazor                    
Blazor (ASP.NET Core hosted)                      blazorhosted          [C#]              Web/Blazor/Hosted             
Blazor Library                                    blazorlib             [C#]              Web/Blazor/Library            
Blazor (Server-side in ASP.NET Core)              blazorserverside      [C#]              Web/Blazor/ServerSide         
Blazor (client-side)                              blazor                [C#]              Web/Blazor/Standalone         
ASP.NET Core Empty                                web                   [C#], F#          Web/Empty                     
ASP.NET Core Web App (Model-View-Controller)      mvc                   [C#], F#          Web/MVC                       
ASP.NET Core Web App                              webapp                [C#]              Web/MVC/Razor Pages           
ASP.NET Core with Angular                         angular               [C#]              Web/MVC/SPA                   
ASP.NET Core with React.js                        react                 [C#]              Web/MVC/SPA                   
ASP.NET Core with React.js and Redux              reactredux            [C#]              Web/MVC/SPA                   
Razor Class Library                               razorclasslib         [C#]              Web/Razor/Library/Razor Class Library
ASP.NET Core Web API                              webapi                [C#], F#          Web/WebAPI                    
ASP.NET Core gRPC Service                         grpc                  [C#]              Web/gRPC                      
global.json file                                  globaljson                              Config                        
NuGet Config                                      nugetconfig                             Config                        
Dotnet local tool manifest file                   tool-manifest                           Config                        
Web Config                                        webconfig                               Config                        
Solution File                                     sln                                     Solution                      

Examples:
    dotnet new mvc --auth Individual
    dotnet new webconfig
    dotnet new --help
PS C:\Users\My User\Desktop\Blazor>

@ramimod Can you open a new issue so I (or others) can try to help you? I don't think your problem is related to mine so there's no reason to use this thread

You intended to execute a .NET Core program, but dotnet-C:Users\Ricardo does not exist.

@SteveSandersonMS Looks like the Blazor self-host template might have issues when the user has spaces in their user name?

@danroth27 I created a new account with no spaces (rribeiro) and it worked.

D:\>mkdir test4 && cd test4

D:\test4>dotnet new blazor
The template "Blazor (client-side)" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on D:\test4\test4.csproj...
  Restore completed in 3,14 sec for D:\test4\test4.csproj.

Restore succeeded.


D:\test4>dotnet run
Hosting environment: Production
Content root path: D:\test4
Now listening on: http://localhost:5000
Now listening on: https://localhost:5001
Application started. Press Ctrl+C to shut down.

Thanks @rjmr97 for reporting this. Thanks @pranavkm and @JunTaoLuo for fixing it!

Fixed in https://github.com/aspnet/AspNetCore/pull/9659

I just pulled down the latest templates, etc etc asd per the "Getting Started with Blazor" tutorial and am running into this exact situation. I see the fix was commited, but what can i do to get that fix today? or what is the work around today? Just trying to save time without having to read a bunch on how to call dotnet run with a bunch of switches and parameters. Thanks

I fixed my version by replacing the file C:\Users\USER_NAME\.nuget\packages\microsoft.aspnetcore.blazor.devserver\3.0.0-preview4-19216-03\build\Microsoft.AspNetCore.Blazor.DevServer.props with the one from the fix

That did the trick @rjmr97 thanks for the suggestion!

The issue is due to the space between the username (_C:Users{USER_NAME}_)

The fix is in the Below PR. It did resolve the issue.
https://github.com/aspnet/AspNetCore/pull/9659/files

If still, the issue persists. Delete the Debug & Release folders from bin and restart the vs.

Thanks @pakrym for the fix

Was this page helpful?
0 / 5 - 0 ratings