question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Razor error when building Blazor Client app on MS SDK docker container

See original GitHub issue

Describe the bug

UPDATE: Please see comment below for Docker.develop file that I had missed from this original post.

I have a blazor client project & asp.net core server project in my solution. I thought i’d have a go at deploying it to an AKS cluster using visual studio “dev spaces” This basically adds a DOCKER file to project which copies your source code into a build container and does the build of the solution inside that container.

Here is the DOCKERFILE that was generated for me:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS build
WORKDIR /src
COPY ["Hub.Platform.Client/Hub.Platform.Client.csproj", "Hub.Platform.Client/"]
COPY ["Hub.Platform.Core/Hub.Platform.Core.csproj", "Hub.Platform.Core/"]
COPY ["Hub.Platform.Server/Hub.Platform.Server.csproj", "Hub.Platform.Server/"]
COPY ["Hub.Platform.Shared/Hub.Platform.Shared.csproj", "Hub.Platform.Shared/"]

RUN dotnet restore "Hub.Platform.Server/Hub.Platform.Server.csproj"
COPY . .
WORKDIR "/src/Hub.Platform.Server"
RUN dotnet build "Hub.Platform.Server.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "Hub.Platform.Server.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Hub.Platform.Server.dll"]

When this runs, the build fails at the following step with this output:

Step 14/16 : RUN dotnet build --no-restore “Hub.Platform.Server.csproj” -c $BUILD_CONFIGURATION —> Running in 5db3c6447be5 Microsoft ® Build Engine version 16.0.462+g62fb89029d for .NET Core Copyright © Microsoft Corporation. All rights reserved. /usr/share/dotnet/sdk/3.0.100-preview5-011568/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/src/Hub.Platform.Server/Hub.Platform.Server.csproj] /usr/share/dotnet/sdk/3.0.100-preview5-011568/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(157,5): message NETSDK1057: You are using a preview version of .NET Core. See: https://aka.ms/dotnet-core-preview [/src/Hub.Platform.Core/Hub.Platform.Core.csproj] Hub.Platform.Shared -> /src/Hub.Platform.Shared/bin/Debug/netstandard2.0/Hub.Platform.Shared.dll WritableOptions/WritableOptions.cs(13,26): warning CS0618: ‘IHostingEnvironment’ is obsolete: ‘This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Hosting.IHostEnvironment.’ [/src/Hub.Platform.Core/Hub.Platform.Core.csproj] WritableOptions/WritableOptions.cs(20,13): warning CS0618: ‘IHostingEnvironment’ is obsolete: ‘This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Hosting.IHostEnvironment.’ [/src/Hub.Platform.Core/Hub.Platform.Core.csproj] WritableOptions/ServiceCollectionExtensions.cs(19,55): warning CS0618: ‘IHostingEnvironment’ is obsolete: ‘This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.Extensions.Hosting.IHostEnvironment.’ [/src/Hub.Platform.Core/Hub.Platform.Core.csproj] Pages/Index.razor(43,24): warning CS1998: This async method lacks ‘await’ operators and will run synchronously. Consider using the ‘await’ operator to await non-blocking API calls, or ‘await Task.Run(…)’ to do CPU-bound work on a background thread. [/src/Hub.Platform.Client/Hub.Platform.Client.csproj] Pages/Index.razor(43,24): warning CS1998: This async method lacks ‘await’ operators and will run synchronously. Consider using the ‘await’ operator to await non-blocking API calls, or ‘await Task.Run(…)’ to do CPU-bound work on a background thread. [/src/Hub.Platform.Client/Hub.Platform.Client.csproj] Hub.Platform.Client -> /src/Hub.Platform.Client/bin/Debug/netstandard2.0/Hub.Platform.Client.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: Hub.Platform.Client, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null Output action: Save assembly: Hub.Platform.Shared, 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: Link 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: /src/Hub.Platform.Client/obj/Debug/netstandard2.0/blazor/blazor.boot.json Blazor Build result -> 23 files in /src/Hub.Platform.Client/bin/Debug/netstandard2.0/dist It was not possible to find any compatible framework version The specified framework ‘Microsoft.NETCore.App’, version ‘2.0.9’ was not found.

  • The following frameworks were found: 3.0.0-preview5-27626-15 at [/usr/share/dotnet/shared/Microsoft.NETCore.App] You can resolve the problem by installing the specified framework and/or SDK. The .NET Core frameworks can be found at:
  • https://aka.ms/dotnet-download /root/.nuget/packages/microsoft.aspnetcore.razor.design/2.2.0/build/netstandard2.0/Microsoft.AspNetCore.Razor.Design.CodeGeneration.targets(79,5): error : rzc discover exited with code 150. [/src/Hub.Platform.Core/Hub.Platform.Core.csproj] Build FAILED.

Note, the razor error. The DOCKERFILE was generated for me by Azure Dev Spaces functionality within Visual Studio. Do I need to be using different base docker images in order to build a blazor application?

To Reproduce

Steps to reproduce the behavior:

  1. Create a new Blazor client app hosted by an asp.net core web site project, using latest VS2019 preview.
  2. Follow this getting started to use Dev Spaces and deploy the solution to an AKS cluster: https://docs.microsoft.com/en-us/azure/dev-spaces/quickstart-netcore-visualstudio
  3. The exception occurs during the docker container build step.

Expected behavior

Build should succeed.

Additional context

Add any other context about the problem here. Include the output of dotnet --info

dotnet --info .NET Core SDK (reflecting any global.json): Version: 3.0.100-preview5-011568 Commit: b487ff10aa

Runtime Environment: OS Name: Windows OS Version: 10.0.17134 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview5-011568\

Host (useful for support): Version: 3.0.0-preview5-27626-15 Commit: 61f30f5a23

.NET Core SDKs installed: 1.1.13 [C:\Program Files\dotnet\sdk] 2.1.502 [C:\Program Files\dotnet\sdk] 2.1.503 [C:\Program Files\dotnet\sdk] 2.1.504 [C:\Program Files\dotnet\sdk] 2.1.505 [C:\Program Files\dotnet\sdk] 2.1.507 [C:\Program Files\dotnet\sdk] 2.1.600 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.1.700-preview-009601 [C:\Program Files\dotnet\sdk] 2.1.700-preview-009618 [C:\Program Files\dotnet\sdk] 2.1.800-preview-009677 [C:\Program Files\dotnet\sdk] 2.2.101 [C:\Program Files\dotnet\sdk] 3.0.100-preview5-011568 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] 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.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] 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.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview5-19227-01 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.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.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-preview5-27626-15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dazinatorcommented, Jun 5, 2019

Ah ok so…

Perhaps its this…

My solution structure looks like this:

Hub.Platform.Client references Hub.Platform.Shared Hub.Platform.Server references Hub.Platform.Shared Hub.Platform.Server references Hub.Platform.Core Hub.Platform.Server references Hub.Platform.Client

Hub.Platform.Core.csproj is probably the culprit - it’s csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="Views\Platform\site.css" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
    <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="3.0.0-preview5.19227.9" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="3.0.0-preview5.19227.9" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.0.0-preview5.19227.9" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Views\Shared\" />
  </ItemGroup>

</Project>

It’s a razor class library and it’s using mvc 2.x doh!

Sorry that’s slightly embarrassing. Still I guess there are going to be reusable razor view nuget packages out there that were compiled targeting asp.net 2.X that will be referenced from 3.X mvc applications - i.e so do we actually care about this use case? In my view, the sdk 3 docker image should be able to build projects that indirectly pull in 2.x references ?

1reaction
dazinatorcommented, Jun 5, 2019

Nope. Here is my Blazor client csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <RestoreAdditionalProjectSources>
      https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json;
      https://dotnet.myget.org/F/blazor-dev/api/v3/index.json;
    </RestoreAdditionalProjectSources>
    <LangVersion>7.3</LangVersion>
    <RazorLangVersion>3.0</RazorLangVersion>
  
  </PropertyGroup>

  <ItemGroup>
    
    <PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview5-19227-01" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview5-19227-01" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Hub.Platform.Shared\Hub.Platform.Shared.csproj" />
  </ItemGroup>

</Project>

By the way I spent all day on this and managed to get the build to suceed by installing dotnet core sdk 2.1 into the sdk 3.0 docker image. Which wasn’t a straightforward process. Here is a docker file with the ammendments necessary to complete a build:

FROM mcr.microsoft.com/dotnet/core/sdk:3.0
ARG BUILD_CONFIGURATION=Debug
ENV ASPNETCORE_ENVIRONMENT=Development
ENV DOTNET_USE_POLLING_FILE_WATCHER=true
EXPOSE 80

WORKDIR /src

# Issue 1. sudo is not present on this debian 10 based image. Need sudo for other steps in the resolution.
RUN apt-get update && apt-get install -y sudo

# Issue 2. apt-get install fails for dot net packages, becuase we need to add the microsoft package sources to the apt-get sources lists.
RUN wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.asc.gpg
RUN sudo mv microsoft.asc.gpg /etc/apt/trusted.gpg.d/
RUN sudo chown root:root /etc/apt/trusted.gpg.d/microsoft.asc.gpg

RUN wget -q https://packages.microsoft.com/config/debian/9/prod.list
RUN sudo mv prod.list /etc/apt/sources.list.d/microsoft-prod.list
RUN sudo chown root:root /etc/apt/sources.list.d/microsoft-prod.list

# Not sure what this does but I think its necessary after modifying the sources lists..
RUN sudo apt-get update

# apt-get install still fails for dotnet sdk 2.1 as it says there are missing libraries. Must install these manually.
RUN wget http://debian.mirrors.uk2.net/pool/main/i/icu/libicu57_57.1-6+deb9u2_amd64.deb
RUN wget http://debian.mirrors.uk2.net/pool/main/o/openssl1.0/libssl1.0.2_1.0.2r-1~deb9u1_amd64.deb

RUN dpkg -i libicu57*.deb
RUN dpkg -i libssl1.0.2*.deb

# Now we can install dotnet sdk 2.1...
RUN sudo apt-get install -y dotnet-sdk-2.1

# Finally we can build a blazor server project that references a blazor client project.
COPY ["Hub.Platform.Client/Hub.Platform.Client.csproj", "Hub.Platform.Client/"]
COPY ["Hub.Platform.Core/Hub.Platform.Core.csproj", "Hub.Platform.Core/"]
COPY ["Hub.Platform.Server/Hub.Platform.Server.csproj", "Hub.Platform.Server/"]
COPY ["Hub.Platform.Shared/Hub.Platform.Shared.csproj", "Hub.Platform.Shared/"]
RUN dotnet new -i Microsoft.AspNetCore.Blazor.Templates::3.0.0-preview5-19227-01
RUN dotnet restore "Hub.Platform.Server/Hub.Platform.Server.csproj"
COPY . .
WORKDIR "/src/Hub.Platform.Server"
RUN dotnet build --no-restore "Hub.Platform.Server.csproj" -c $BUILD_CONFIGURATION

RUN echo "exec dotnet run --no-build --no-launch-profile -c $BUILD_CONFIGURATION --" > /entrypoint.sh

ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error building Docker image for Blazor WebAssembly ...
I create a solution with 4 poject, I'm facing difficulties when trying to build a Docker image for my Blazor WebAssembly project.
Read more >
Host and deploy ASP.NET Core Blazor WebAssembly
Learn how to host and deploy Blazor WebAssembly using ASP.NET Core, Content Delivery Networks (CDN), file servers, and GitHub Pages.
Read more >
Containerising a Blazor WebAssembly App
In this post, I show how to containerise a Blazor WebAssembly App using Docker. Highlighting the different requirements when compared to ...
Read more >
Why isn't my ASP.NET Core app in Docker working?
In this post I describe a problem where my ASP.NET Core app in Docker wasn't responding to requests. This post debugs and diagnoses...
Read more >
How to Build and Secure Web Applications with Blazor
Learn how to build client-side Web apps using Blazor and how to secure them with Auth0 authentication and authorization features.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found