Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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)

like image 934
tomRedox Avatar asked Feb 03 '21 18:02

tomRedox


People also ask

Where do I deploy Blazor WebAssembly?

Blazor WebAssembly apps can be deployed to Azure App Services on Windows, which hosts the app on IIS. Deploying a standalone Blazor WebAssembly app to Azure App Service for Linux isn't currently supported.

Is Blazor WebAssembly client-side?

Run on WebAssembly or the serverBlazor can run your client-side C# code directly in the browser, using WebAssembly. Because it's real . NET running on WebAssembly, you can re-use code and libraries from server-side parts of your application. Alternatively, Blazor can run your client logic on the server.


1 Answers

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

like image 63
tomRedox Avatar answered Sep 17 '22 16:09

tomRedox