Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net 5 - Azure Pipeline - The SDK 'Microsoft.NET.Sdk.BlazorWebAssembly' specified could not be found

I just upgraded a Blazor Web Assembly solution to .Net 5 and I'm getting the following error in an Azure Pipeline in the NuGet Command step:

error MSB4236: The SDK 'Microsoft.NET.Sdk.BlazorWebAssembly' specified could not be found

The azure-pipelines.yml file is the following:

trigger:
- develop

pool:
  vmImage: 'windows-latest'

variables:
  solution: 'SomeProjectNew.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

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

- task: VSBuild@1
  inputs:
    solution: 'SomeProjectNew.sln'
    msbuildArgs: '/p:DeployOnBuild=true /p:PublishProfile=SomeProject-demo /p:Password=$(SomeProjectDemoWebDeployPassword)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

Am I missing some step in the pipeline configuration to make this work with .Net 5 and the new blazor sdk?

like image 919
Augusto Barreto Avatar asked Nov 12 '20 16:11

Augusto Barreto


2 Answers

Since you are using .Net 5, instead of using Nuget command, try to use Use .net core taskand Dotnet core task with restore command.

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100-rc.1.20452.10'
  inputs:
    packageType: 'sdk'
    version: '5.0.100'
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

It's strongly recommended to use dotnet restore and dotnet build tasks for projects that target .net core. See this statement from Nuget task:

Also take a look at this similar question here: Azure CI pipeline for Blazor .NET 5 doesn't work

like image 163
PatrickLu-MSFT Avatar answered Sep 20 '22 22:09

PatrickLu-MSFT


Just in case somebody else is after the full yml file, here is what I ended up with:

trigger:
- develop

pool:
  vmImage: 'windows-latest'

steps:

- task: UseDotNet@2
  displayName: 'Install .NET 5 SDK'
  inputs:
    packageType: 'sdk'
    version: '5.x'
    
- task: DotNetCoreCLI@2
  displayName: 'Restore Nuget Packages'
  inputs:
    command: 'restore'
    projects: 'SomeSolution.sln'
    feedsToUse: 'config'
    nugetConfigPath: '.nuget/NuGet.config'

- task: DotNetCoreCLI@2
  displayName: 'Publish to Azure'
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: 'SomeProjectFolder/SomeWebProject.csproj'
    arguments: '/p:PublishProfile=profile-name /p:Password=$(WebDeployPassword)'
    zipAfterPublish: false
    modifyOutputPath: false

My publish profile uses web deploy to deploy the app to an Azure App Service. This approach relies on a '.nuget/NuGet.config' file in source control, and a secret variable $(WebDeployPassword) defined on the pipeline (Secret Variables).

like image 26
Augusto Barreto Avatar answered Sep 20 '22 22:09

Augusto Barreto