Aspnetcore: Default Blazor Client App fails throwing the build error[Blazor][Appbuilding]

Created on 30 Jul 2019  路  19Comments  路  Source: dotnet/aspnetcore

I am trying to create an ClientSide Blazor app but I am not even able to build the default blazor app present in the VS

C:\Users\anagniho\source\repos\BlazorApp8>dotnet build
Microsoft (R) Build Engine version 16.3.0-preview-19375-05+42c4c1370 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 30.65 ms for C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj.
  You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview
obj\Debug\netstandard2.0\RazorDeclaration\Pages\_Imports.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\_Imports.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\FetchData.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\FetchData.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Index.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Index.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Counter.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Counter.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]

Build FAILED.

obj\Debug\netstandard2.0\RazorDeclaration\Pages\_Imports.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\_Imports.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\FetchData.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\FetchData.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Index.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Index.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Counter.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttributeAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
obj\Debug\netstandard2.0\RazorDeclaration\Pages\Counter.razor.g.cs(51,38): error CS0234: The type or namespace name 'LayoutAttribute' does not exist in the namespace 'Microsoft.AspNetCore.Components' (are you missing an assembly reference?) [C:\Users\anagniho\source\repos\BlazorApp8\BlazorApp8.csproj]
    0 Warning(s)
    8 Error(s)

Time Elapsed 00:00:01.21

Selecting the server app question resolves the issue though. is there anything else that needs to be installed for making it work ?

area-blazor question

All 19 comments

Thanks for contacting us, @Anipik .
Looks like you have outdated client-side templates. Please reinstall the templates as specified at: https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started?view=aspnetcore-3.0&tabs=visual-studio

@mkArtakMSFT I followed the instructions specified in the linked webpage but I get the same error.
When I create the clientside blazor app the Source shown by VS is CLI v5.0.100-alpha-01013627

any update on this issue?

I am getting the same error using the latest Visual Studio Enterprise Preview with the latest templates preview 8 and latest .Net Core 3.0 preview 8.

@Anipik, seems like you've got some nighly builds where the build of the SDK was from master branch, which is for .Net Core 5 release. Have you tried uninstalling all the 3.0 SDKs you have and reinstall the official .Net Core 3.0 Preview 8 SDK?

@PSharp93
I remove all template folders except
v3.0.100-preview8-013656/
in
C:/Users/xx/.templateengine/dotnetcli/ and it works fine now

Can't get it to work using any of the things mentioned here.
Running on preview 8, but the samples have dependencies on preview 6 of the nuget packages.

When trying to update the NuGet packages, I find that Microsoft.AspNetCore.Components.Browser is only in preview7 on Nuget.org. Did someone forget to release something?

https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Browser/

Looks like the code generation misses the Layout part of this namespace:
Microsoft.AspNetCore.Components.Layouts.LayoutAttribute

@erikbra the package Microsoft.AspNetCore.Components.Browser was renamed to `Microsoft.AspNetCore.Components.Web.

@PSharp93
I remove all template folders except
v3.0.100-preview8-013656/
in
C:/Users/xx/.templateengine/dotnetcli/ and it works fine now

Unfortunately did not work for me, still getting the errors using:

  • VS 2019 16.3.0 Preview 2.0
  • .NET Core SDK 3.0.100 - preview 8 (x64)
  • Blazor Templates v3.0.100-preview8-013656

Visual Studio shows updates for 4 Nuget packages but updating them causes new build errors.

@PSharp93
I remove all template folders except
v3.0.100-preview8-013656/
in
C:/Users/xx/.templateengine/dotnetcli/ and it works fine now

Unfortunately did not work for me, still getting the errors using:

  • VS 2019 16.3.0 Preview 2.0
  • .NET Core SDK 3.0.100 - preview 8 (x64)
  • Blazor Templates v3.0.100-preview8-013656

Visual Studio shows updates for 4 Nuget packages but updating them causes new build errors.

After deleting all templates and reinstalling the v3.0.100-preview8-013656 template, now only "Blazor Server App" and "Blazor WebAssembly App" is available as project type and those work. Was the mixed project type with client + server side removed?

Yes, the templates have been renamed. You can read more about that change in the 'Blazor templates renamed and simplified' section in the Preview 8 Release Blog Post

After deleting all templates and reinstalling the v3.0.100-preview8-013656 template, now only "Blazor Server App" and "Blazor WebAssembly App" is available as project type and those work. Was the mixed project type with client + server side removed?

Created a PR in the blazor-workshop repo to upgrade to 3.0.0-preview8 https://github.com/dotnet-presentations/blazor-workshop/pull/133

I hit this issue when using the latest VS 2019 preview 2 to build my solution. My solution was pinned via a global.json file to use sdk preview 7, but I didn't have sdk preview 7 installed, so the build rolled forward to use sdk preview 8. I have blazor preview 7 dependencies in my dependency graph, and it appears building under preview 8 with preview 7 dependencies, produced this error.

Rather than upgrade everything to preview 8 (some dependencies I use aren't compiled and released for preview 8 yet and are still on preview 7) I did this to resolve:

  1. Install preview 7 sdk
  2. Ensure all dependencies in my application that target blazor are referencing preview 7 (not 6 or less)
  3. Add a global.json to my solution to pin to preview 7.
  4. run a dotnet build - success.
  5. I had VS open throughout this, a rebuild doesn't seem to detect sdk 7 was installed and continues to use sdk 8 and fail - restarting VS, and reloading the solution, and then rebuilding - then correctly used sdk 7 and the build succeeded.

I assume this exact same thing can occur each time we go from preview x to preview y - lot of breaking changes at the moment - the build system seems to be very fragile - a bit like goldilocks porridge - everything has to be be "just right" :-)

replace it with

Microsoft.AspNetCore.Components.Layouts.LayoutAttribute

Every time I replace Microsoft.AspNetCore.Components.LayoutAttribute in my classes with Microsoft.AspNetCore.Components.Layouts.LayoutAttribute, it reverts back to the original code. How do I stop that? What am I missing?

@GaryTuttle1 Install dotnet sdk 3.0.0 preview 8 and make sure you build with that (check your global.json if you are using one, and do dotnet --list-sdks to make sure you have preview 8). I also uninstalled sdk preview 7. Restarted vs (update vs to 16.3.0 preview 2, and uninstall the blazor extension if you have it installed). Made sure all my blazor dependencies were targeted against preview 8. ..Once I did all of that my issue with layout attribute went away, but there are other breaking changes in .razor files to address, read the preview 8 announcement for what they are (things like @ref suppress field etc))

Is there a single, definitive guide that says how to do this? I'd like to work with some of the tutorials out there, but I have this same problem. I've tried with 2019 Preview and 2019 non-preview with the preview SDK option checked. There are lots of little pieces of "try this" and "I did that" sprinkled all over the internet, but trying to chase them down is a recipe for making all sorts of random, wild-guess, conflicting changes to my PC.

This will allow you to create a new project from the Blazor App (web assembly) template which compiles out the box. Any existing project will probably continue to have build errors. Projects may break between Visual Studio updates and you will have to do this again. You may need to create a new project from the fresh template and pull your existing source into it. Server side / SignalR does not seem to suffer from these build errors.

Credit to Tim Corey for the powershell method https://www.youtube.com/watch?v=CaxR4_fP-FA

I don't think this is necessary, but as part of my troubleshooting I'll include it: You may also need to get the latest .net 3.0 SDK from https://dotnet.microsoft.com/download/visual-studio-sdks
However, if you look in project properties in your Blazor app, Application > Target framework, you will see .NET standard 2.0. Other example projects I've seen on github also have this target framework in the .csproj file.

Thank you for contacting us. Due to no activity on this issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaximRouiller picture MaximRouiller  路  338Comments

radenkozec picture radenkozec  路  114Comments

zorthgo picture zorthgo  路  136Comments

davidfowl picture davidfowl  路  126Comments

danroth27 picture danroth27  路  130Comments