Blazor WebAssembly Azure DevOps build pipeline publish artifacts - azure-devops

We created a build pipeline yaml for our blazor webassembly project that includes a publish task. For some reason only the wwwroot folder items get generated into the drop folder, and all the other binaries that are normally located outside of the wwwroot folder are not generated for some reason.
Here is part of the yaml file that builds and publishes. Is it setup incorrectly to get all the files generated and published, or is it just that it will only give us the static files being a webassembly project?
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration) --output $(build.artifactstagingdirectory)"'
zipAfterPublish: false
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifact'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
condition: succeededOrFailed()
Also, since we are finding that Blazor webassembly has an issue using the Azure configuration settings for a web service, we are needing to have the publish process manipulate the web.config file so we can set the ASPNETCORE_ENVIRONMENT of the build and deploy. Everything I have found so far does not work when run in the DevOps build pipeline, as they are meant for dotnet scripts.
Does anyone know how this can be done? We have tried to add site /p:EnvironmentName=Development to the --output argument of the publish task, but it says it cannot run on multiple projects, even though we set the projects argument to just the one (it is not shown above as we put it back to normal for now).
Thank you,
Chris Calvert

Did you try this?
task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(buildConfiguration) --output "$(build.artifactstagingdirectory)" /p:EnvironmentName=Development'
zipAfterPublish: True

Related

How to deploy multiple artifacts in a release using Azure devops

We are planning to migrate our current CICD setup which includes Jira and Jenkins, to Azure DevOps but we need suggestion how we can tackle below scenario in Azure DevOps:
We have multiple artifacts in Jira ticket( which can varies from 10 to 200). When we move the ticket to different column in kanban board it triggers jenkins deployment job which deploys all these artifacts at once as one release
But we are not able to find how we can achieve this in azure releases, as it only allows one artifacts in one release. How can we deploy multiple artifacts like above in a release
You could simplify it so instead of deleting the content how about put each artifact in a sub folder of the $(Build.ArtifactStagingDirectory) So by just appending /Api or /App I could create specific publish folders that I could then push onto the azure pipeline.
You can then have as many artifacts as you need.
The important parts to take from this are that publishWebProjects needs to be set to false or it defaults to true and then ignores the projects line below, and the output path puts the content in a sub folder.
# This need to be false in order for the specific project to be published
publishWebProjects: False
projects: '**/DevOpsApp.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/App'
and pathtoPublish need to then point to the sub folder
pathtoPublish: '$(Build.ArtifactStagingDirectory)/App'
Full example file below:
steps:
- task: DotNetCoreCLI#2
displayName: 'Build'
inputs:
command: 'build'
projects: '**/DevOpsApi.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/*Tests.csproj'
arguments: '--configuration $(buildConfiguration)'
testRunTitle: 'Unit Tests'
# Publish the artifact
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
# This need to be false in order for the specific project to be published
publishWebProjects: False
projects: '**/DevOpsApi.csproj'
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)/Api'
zipAfterPublish: True
# Publish the artifact for the pipelines to use
- task: PublishBuildArtifacts#1
displayName: 'Publishing WebAPI Artifact'
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)/Api'
artifactName: 'TestWebApi-Wip'

Working directory parameter of DotNetCoreCL Publish step

I have a repository with many solutions in it. I'd like to set up a build pipeline in Azure DevOps and build specific solution. I only need the "standard" steps as "restore packages, build, run unit tests, publish". However, the "publish" step gives me a headache.
The folder hierarchy for the repository looks like this:
src
- Solution1
- Project1
- Project2
- Project3
- Solution2
- Project4
- Project5
...
My goal would be to publish only the projects of e.g. Solution2 - so Project4 and Project5. Setting the value of workingDirectory to "src/Solution2" or "$(System.DefaultWorkingDirectory)/src/Solution2" don't work as I expected.
Here's the definition of the build step.
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
workingDirectory: src/Solution2
In the logs, I see
"C:\Program Files\dotnet\dotnet.exe" publish [path_to_agent]_work\1\s\src\Solution1\Project1\Project1.csproj --configuration Release --output [path_to_agent]_work\1\a\Project1
and similar entries for every single project in the repository.
As a workaround I tried using the "custom" command, but it didn't work out either.
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: custom
arguments: 'src/Solution2 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory) '
custom: publish
This produces a log entry as
"C:\Program Files\dotnet\dotnet.exe" publish [path_to_agent]_work\1\s\src\Solution1\Project1\Project1.csproj src/Solution2 --configuration Release --output [path_to_agent]_work\1\a\Project1
and eventually the pipeline fails as Only one project can be specified.
Any ideas what I'm doing wrong?
I had the same problem. After a lot of trials and errors I came to the conclusion that the workingdirectory parameter is just ignored as explained here.
Also I noticed globbing (**/*) does not work if you use quotes. Also publishWebProjects has to be set to false otherwise it will start searching for other projects from the default working folder.
So this worked for me:
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
configuration: $(buildConfiguration)
projects: |
$(System.DefaultWorkingDirectory)/pathToProjectA/projectA.csproj
$(System.DefaultWorkingDirectory)/pathToProjectB/*.csproj
You can try to use projects settings with globbing to get all csproj's:
- task: DotNetCoreCLI#2
displayName: 'dotnet publish'
inputs:
command: 'publish'
publishWebProjects: false
projects: 'src/Solution2/**/*.csproj'
arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
zipAfterPublish: true
modifyOutputPath: true

Error deploying a folder artifact to Azure app service

I'm using Azure Dev Ops to run my build and release pipelines. I've got a build script that publishes my web code to an artifact folder (using .NET SDK projects), and I just need to push this code into my Azure app service. I've tried the "Azure app service deploy" and "Deploy code to app service" tasks in the release pipeline, giving it the publish settings file from my Azure instance and pointing to the folder with my code (since it says it takes zip or folder). On the console at this step, however, I get an error message of "No such deploying method exists."
I was able to get things pushed through FTP but I'd like to understand why the app service publish didn't work, as there are options (like deployment slots) that might be needed in the future. Is this a scenario where using the Azure resource manager connection would work better? Or does my build artifact need to be zipped after all? If it has to be zipped as a web deploy, is there a step to do this after a solution build, because I have to copy files into the artifact folder for transforms first, so I can't just do a comprehensive web build/zip.
I don't see details of your pipeline so I would share mine. I'm deploying zip package:
In Package or folder dialog I have:
I use YAML in my pipelines but it is easy to understand and follow if you want to have similar in classic pipelines:
trigger: none
pr: none
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
projectDirectory: 'app-service-deployment-to-slot-with-preview\hadar'
steps:
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
workingDirectory: $(projectDirectory)
- task: DotNetCoreCLI#2
displayName: Publish
inputs:
command: publish
publishWebProjects: false
projects: '$(projectDirectory)\hadar.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: CopyFiles#2
displayName: 'Copy configuration settings checks'
inputs:
contents: app-service-deployment-to-slot-with-preview\scripts\**
targetFolder: '$(Build.ArtifactStagingDirectory)\scripts'
flattenFolders: true
- task: PublishBuildArtifacts#1
displayName: 'Publish Artifacts'

Trying to publish a build to Nuget.org

I'm new to Azure DevOps; however, what I'm doing seems like it should be straightforward: I simply want to compile a project and publish to NuGet.org. I'm hitting that many barriers to doing it that I feel that I'm probably mis-using the tool.
I have a build which looks like this:
trigger:
- master
pool:
vmImage: 'windows-2019'
variables:
buildConfiguration: 'Release'
steps:
- script: dotnet build --configuration $(buildConfiguration) /property:Version=$(Build.BuildNumber)
displayName: 'dotnet build $(buildConfiguration)'
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
This successfully builds. However, I do get the following warning:
##[warning]Directory 'd:\a\1\a' is empty. Nothing will be added to build artifact 'drop'.
When I try to deploy, I'm getting errors - the latest of which is:
No files matched the search pattern.
In dotnet pack, here's the release step for pack:
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: '$(System.DefaultWorkingDirectory)/name.project'
This is what's currently failing, but the next step is intended to publish to NuGet (for completeness - and incase there's an easier way to do all this):
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: '$(System.DefaultWorkingDirectory)/name.project'
The release has an artifact, which I've set up as the output from the build (I think); however, I get the error from this:
No version is available for name.project or the latest version has
no artifacts to publish. Please check the source pipeline.
My understanding of how this should work in general is that the Build should hold the steps involved in producing the binaries, etc, whereas the Release should be any steps involved in deploying the built. So, I should be able to take a 'Build' and 'Release' it several times to multiple locations. I feel like this understanding is not in-keeping with the errors that I'm seeing.
Is my understanding correct?
What could I be doing wrong here and, more importantly, what are the methods of diagnosing issues with this?
Trying to publish a build to Nuget.org
For the first error, that because you are mising the Copy Files task before using the Publish Build Artifacts task.
Check the Publish Build Artifacts task, you can view this task is used to publish build artifacts to Azure Pipelines, TFS, or a file share.
But after build the project/solution, the output are stored on the build agent, rather than the artifacts. So we need to add a copy task before PublishBuildArtifacts to copy the files from output to the artifacts:
steps:
- task: CopyFiles#2
displayName: 'Copy Files to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: '$(system.defaultworkingdirectory)'
TargetFolder: '$(build.artifactstagingdirectory)'
enabled: false
For the second error, you should specify the project in the repos instead of System.DefaultWorkingDirectory, where is use to build the project, change the Path to csproj in the repos:
steps:
- task: DotNetCoreCLI#2
displayName: 'dotnet pack'
inputs:
command: pack
packagesToPack: NetCoreDemo/NetCoreDemo/NetCoreDemo.csproj
Hope this helps.
You man need to provide the --output argument for dotnet build. Add the following
--output $(Build.ArtifactStagingDirectory)
so the command should look something like this.
dotnet build --configuration $(buildConfiguration) /property:Version=$(Build.BuildNumber) --output $(Build.ArtifactStagingDirectory)
this will put the output into the Artifact Staging Directory (d:\a\1\a)
which will include the *.nupkg file.
I am assuming you are using the new CSProj format and you are supplying the properties for the NuGet package and have the <GeneratePackageOnBuild>true</GeneratePackageOnBuild> property already set. If so the *.nupkg file should be in the output directory that you define in the dotnet build command. Then you don't need to use dotnet pack. In the release definition you just need to use the NuGet task and use push command to push the package to your NuGet Feed.
Use this blog post as reference. It does not have the full details since its focusing only on few aspects of the entire process. but it should be helpful to get the build aspect correct.

Working Azure DevOps (aka VSTS) Build Definition for nopCommerce 4.xx

Did any got a working Build Definition in Azure DevOps working for nopCommerce 4.xx working? If so will you please share the YAML-file. I tried several possible solutions, but I don't get it work.
I used the default ASP.NET Core template from Azure Devops. See below YAML
content: resources:
- repo: self queue: name: Hosted Ubuntu 1604
steps:
- task: DotNetCoreCLI#2 displayName: Restore inputs:
command: restore
projects: '$(Parameters.RestoreBuildProjects)'
- task: DotNetCoreCLI#2 displayName: Build inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2 displayName: Test inputs:
command: test
projects: '$(Parameters.TestProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2 displayName: Publish inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
zipAfterPublish: True
- task: PublishBuildArtifacts#1 displayName: 'Publish Artifact' inputs:
PathtoPublish: '$(build.artifactstagingdirectory)'
At the Build step it gives errors when trying to build the Plugins:
2018-12-16T20:31:51.2431313Z
/home/vsts/work/1/s/src/Build/ClearPluginAssemblies.proj(21,5): error
MSB3073: The command "dotnet
"/home/vsts/work/1/s/src/Build\ClearPluginAssemblies.dll"
"OutputPath=/home/vsts/work/1/s/src/Build/../Presentation/Nop.Web/bin/Release/netcoreapp2.1/|PluginPath=/home/vsts/work/1/s/src/Plugins/Nop.Plugin.DiscountRules.CustomerRoles/../../Presentation/Nop.Web/Plugins/DiscountRules.CustomerRoles/|SaveLocalesFolders=""
exited with code 1.
Anyone an idea how to get this working?
Edit:
The response of Eriawan give me some insight to look further. I investigated the csproj files of one of the Plugins and see there the next section:
Thank you for your response. It took me closer to the root cause of the problem (hopefully). I investigated one of the csproj file of the PlugIns of nopCommerce and I see the following section
<!-- This target execute after "Build" target -->
<Target Name="NopTarget" AfterTargets="Build">
<!-- Delete unnecessary libraries from plugins path -->
<MSBuild Projects="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" Properties="PluginPath=$(MSBuildProjectDirectory)\$(OutDir)" Targets="NopClear" />
</Target>
Is there a way to turn off these extra execution during build? or to get this work during build, without adjust the csproj file (because I want to adopt future changes of the project)?
If you are using YAML as option for your Azure Pipelines, you should pay attention to the sequence for the build. Also don't mix YAML with build definition, because YAML is different from the old build definition used by TFS and VSTS (before it changed name to be Azure DevOps).
Looking at the YAML, you should have a full build on your DotNetCoreCLI#2 task, by executing command build. The error you have is a little bit cryptic, but it shows that you just execute dll directly and this means you are going to execute the dll instead of doing actual build.
So instead of this:
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
It should be this:
- task: DotNetCoreCLI#2
displayName: Build
command: build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
Notice the additional command: build.