Deploy Blazor WebAssembly App ASP.NET Core hosted to Azure

怎甘沉沦 提交于 2021-02-20 05:20:08

问题


I have a 3-projects solution structure (Client,Server,Shared) in Visual Studio 2019. What I exactly did to create it can be described as:

  • [GUI] BlazorApp -> Blazor WebAssembly App -> checbox ticked [v] ASP.NET Core hosted

which is equal to:

  • [CMD] dotnet new blazorwasm --hosted

I would like to deploy this projects to Azure, but I am facing some problems:

  1. When I tried to use continous GitHub deploy and attached my branch to it, I got error which basically said that 3.1 version is not supported (highest was 3.0). It's weird, while setting up WebApp server on Azure I chose .NET Core 3.1 (LTS) option [hosted on Linux, no other option]
  2. If I would like to publish it manually from VS2019, which "project" should I deploy?

I assume that this 3-project template is just a friendly hand from Microsoft so I don't have to create 2 separate project and what I am trying to do could be done just by deploying two separate WebApps:

  1. REST API built with .NET Core 3.1 ( mix .Shared and .Server projects OR just create WebAPI project)
  2. Blazor WebAssembly App (so called client-side)

Although, if this can be done all at once - I would prefer it.


Thank You in advance!


EDIT 1 (10.03.20 10:15)

This is my *.yml file:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish $(buildConfiguration)'
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

- task: PublishBuildArtifacts@1
  displayName: 'publish artifacts'

Configuration of WebApp:

  • Publish: Code

  • Runtime stack: .NET Core 3.1 (LTS)

  • OS: Linux

EDIT 2 (10.03.20 10:31)

Got the following error:

Error: More than one package matched with specified pattern: D:\a\r1\a**.zip. Please restrain the search pattern.*

EDIT 3 (10.03.20 10:15)

Build finally succeded, after I changed the specific zip file from this list (all the items in this folder are visible on a screenshot. I chose WebApp.zip) But - I go to the url and I am only seeing "Your app service is up and running" default screen..


回答1:


I ran into this same issue, instead of going through Github directly, I used Azure DevOps to pull from Github, build and then deploy to my webapp.

You'll find a great tutorial here.

https://youtu.be/jRgLSMlp28U




回答2:


Azure build agents don't have the latest .NET SDK installed. Add this to your yaml file:

- task: UseDotNet@2
  displayName: 'Use latest preview of .Net Core sdk 3.x'
  inputs:
    version: 3.x
    includePreviewVersions: true


来源:https://stackoverflow.com/questions/60555437/deploy-blazor-webassembly-app-asp-net-core-hosted-to-azure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!