How to create a build pipeline for Blazor WebAssembly Hosted app on Azure DevOps that publishes the server project not the client?
Asked Answered
N

1

11

I'm trying to deploy a Blazor WASM Hosted app from our Git repo on our DevOps server using a DevOps Build pipeline and a separate release pipeline.

The project comprises of a Server project and a Client project (as per the standard structure created by the Blazor WebAssembly Hosted template in VS).

I've used the classic editor and the ASP.NET Core template and the site loads, but the console shows HTTP errors connecting to the server, which makes me think I've deployed the Client project not the Server project. I'm pretty sure that's the case because my Drop artifact contains a file called Client.zip.

How can I change this to deploy the Server app instead?

(There are a number of questions on this already, e.g. here, but none of the cover the classic editor approach)

Ninon answered 3/2, 2021 at 18:38 Comment(0)
N
19

This is the complete process that got it working for me:

YAML Approach

I haven't tried this, but this post by muddybeard210 on the GitHub post Blazor WASM ASP.NET Core Hosted Azure Devops Only Publishes Client/Shared folder gave me the clue as to how to get this working in the classic editor.

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/SkillBoard.Server.csproj'
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'

It is important to note that publishWebProjects is set to false. This is because "If true, the task will try to find the web projects in the repository and run the publish command on them. Web projects are identified by presence of either a web.config file or wwwroot folder in the directory." - Azure devops info button

Due to this being true originally, it was selecting Client every time because the CLIENT project has a wwwroot folder. With publishWebProjects set to false, you can specify a particular project with projects and use the traditional wild card characters.

Classic Editor approach

In the pipelines in VS, choose to add a new pipeline:

New pipeline dialog

Click the 'Use the classic editor' link at the bottom

On the next page pick the repo

Select a source dialog

Choose the ASP.NET Core template:

Select a template dialog

That gets you this:

Pipeline edit page

Then, you just need to change some of the settings on the Publish task:

Pipeline edit page - Editing Publish task

On that task, untick 'Publish web projects' so the Path to project(s) box is shown:

Path to project text box

Then click the link icon and choose to Unlink:

Unlinking

And finally enter a path to just your Server project in the format **/YourWebServerProject.csproj:

Path to project

And that's it. When you run the pipeline your drop should now contain a file called Server.zip instead of Client.zip:

Contents of Artifact drop

Ninon answered 3/2, 2021 at 18:38 Comment(2)
Great answer @tomredoxInsufferable
so there's no need to publish the client project?Coaction

© 2022 - 2024 — McMap. All rights reserved.