The following YAML produced only web projects, my repo has 2 web api projects, 1 blazor and one regular asp.net core but only the asp.net core and blazor get published to 'drop' and the web api projects are ignored.
path of my .sln and files
\front-ends\webproject\webproject.csproj - regular razor project,
this gets added to the drop as webproject.zip
\front-ends\blazorproject\blazorproject.csproj - blazor project, this
gets added to the drop as blazorproject.zip
\services\api1\api.csproj - not showing in the drop
\services\api2\api2.csproj - not showing in the drop
trigger:
- master
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet#2
displayName: ".NET Core 6"
inputs:
version: '6.0.x'
packageType: sdk
- task: NuGetCommand#2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
vstsFeed: 'f5775ae3-da0e-4b38-82f0-ce288b91309b'
- task: DotNetCoreCLI#2
displayName: "Publish"
inputs:
command: 'publish'
arguments: '-r win-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
Add publishWebProjects: false to the `task: DotNetCoreCLI#2 (publish) as the default value is true
Related
I have two solutions in my repository (one AppService (.NET Core API project) and another that is containing Azure Functions).
I am having 2 separate build pipelines and 2 separate release pipelines on Azure DevOps:
UserManagementAPI .yml file (API build pipeline):
trigger:
- dev
pool:
vmImage: 'windows-latest'
variables:
solution: '**/UserManagementAPI.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build'
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: DotNetCoreCLI#2
displayName: 'Test'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: pipeline
artifactName: userManagementAPI
UserManagementAPI.Functions .yml file (Functions build pipeline):
trigger:
- dev
pool:
vmImage: 'windows-latest'
variables:
solution: '**/UserManagementAPI.Functions.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#1
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
displayName: 'Build'
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\UserManagement-Function.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Test'
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish'
inputs:
command: publish
publishWebProjects: true
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
- task: PublishPipelineArtifact#1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
publishLocation: pipeline
artifactName: userManagementAPI-functions
The build pipeline for UserManagementAPI is working just fine, artifact is created correctly, there is a zip file with everything included inside. The release pipeline is working fine as well, basically it's an Azure App Service Deploy task, here is the image:
On the other hand, build pipeline or release pipeline for azure functions are not working correctly, here is the artifact generated from UserManagementAPI.Functions build:
If I download the artifact, UserManagementAPI.zip file is containing all the dlls for UserManagementAPI solution (not the functions) and UserManagement-Function.zip is containing some weird data. Here is what is inside of it:
If I go deep into Content folder:
Here I can see my functions folders and bin folder, bin folder is containing all dlls of the functions (but it's too deep I think, it should be at the top of the zip, not inside Content\D_C\a\1\s\UserManagement.Functions\obj\Release\net6.0\PubTmp\Out\bin).
Each of the functions folders are containing one json file, here is one example:
The artifact files are generated in weird way and weird path in my opinion.
Here is the release pipeline of UserManagementAPI.Functions:
Both build pipelines (API and Functions) are executing successfully, they generate artifacts, release pipeline of UserManagementAPI is working fine but release pipeline of UserManagementAPI-Functions is throwing an error:
##[error]Error: Deployment of msBuild generated package is not supported. Change package format or use Azure App Service Deploy task. /home/azureuser/myagent/_work/r35/a/InternalUsers-Functions/userManagementAPI-functions/UserManagement-Function.zip
I have also found an article on stackoverflow having similar issue, but I couldn't solve it using Fernando Magno's suggestion and Leo Liu's suggestion is confusing to me, how can I have App Service for Azure Function.
To be honest, I'm new to release/build pipelines, especially having same repo with 2 solutions, so any help is appreciated here!
I'm developing a very simple API in ASP.NET Core for testing purposes.
I have an endpoint at https://localhost:5678/api/Values/addition/{a}/{b} which just adds number A and B and stores the result in a database.
The database is stored on Azure. In local, the application is running well and connects to my Azure SQL Server database successfully. I have hardcoded the connection string to avoid any complexifications which can result in errors. I'll change it later.
I have also created a Release Pipeline on Azure. First, here is the azure-pipelines.yml :
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
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: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
The release pipeline is triggered whenever a new push is detected on the master branch :
The job triggered is quite simple, it has a Run On Agent which triggers the deployment of my application to an Azure App Service like that :
steps:
- task: AzureRmWebAppDeployment#4
displayName: 'Deploy To Development'
inputs:
azureSubscription: '{MY SUBSCRIPTION ID}'
appType: webAppLinux
WebAppName: '{MY APP SERVICE NAME}'
deployToSlotOrASE: true
ResourceGroupName: '{MY RESOURCEGROUP NAME, SAME AS THE APP SERVICE}'
The build is successful, all jobs run successfully.
I can now navigate to my app service url https://{MY APP SERVICE NAME}.azurewebsites.net and get the welcome page of Azure :
I assume that at this point, I should be able to navigate to https://{MY APP SERVICE NAME}.azurewebsites.net/api/Values/addition/{a}/{b} and get a response from my API but instead of it, I get an error 404. The api endpoint just doesn't exist.
I've hardcoded everything to avoid system errors like non-acccessible external service, my log stream is also empty, and finally I've used kudu to verify that I have a correct web.config on my application. Everything is, I think, well published.
What am I missing here ?
EDIT 1 :
I've modified my Pipeline as following :
# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
pool:
vmImage: ubuntu-latest
variables:
buildConfiguration: 'Release'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'test'
projects: '**/*Tests.csproj'
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
projects: '**/*sln'
feedsToUse: 'select'
vstsFeed: '{MY FEED}'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: false
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
It modified my wwwroot/ of the App Service, but it still doesn't work.
I don't think you're actually pushing the zip to the app service (which would explain the 404). The AzureRmWebAppDeployment#4 task you're using requires a Package or packageForLinux parameter if you use the webAppLinux type (scroll down a bit from here), so that it knows what to publish to your app service.
I am new to azure dev ops and yml files. I recently created an Azure dev ops starter resource for a .NET Core site I built. I connected it to a github repo and pushed some files.
I am getting the error:
Build FAILED.
/home/runner/.dotnet/sdk/3.1.302/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v5.0 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application
I researched the issue and came up with this solution https://stackoverflow.com/questions/65079876/error-msb3644-the-reference-assemblies-for-framework-netframework-version-v5#:~:text=assemblies%20for%20framework%20%22.-,NETFramework%2CVersion%3Dv5.,SDK%20or%20Targeting%20Pack%20installed.
However I have no idea how to actually implement this.
Do I create a separate yml file and it just fixes it when I push it to git?
I tried adding the following block to the devops-starter-workflow.yml file that was autogenerated by azure in the repo when it was auto created :
- task: UseDotNet#2
displayName: 'Use .NET Core sdk 5.0.100'
inputs:
packageType: 'sdk'
version: '5.0.100'
includePreviewVersions: true
- task: DotNetCoreCLI#2
displayName: 'dotnet restore'
inputs:
command: restore
projects: '**/*.csproj'
but I got the error "every step must define a uses or run key"
How do I actually add this to my build? I dont see a pipeline anywhere in my azure portal.
Are you specifying the MS Agent vs2017-win2016
Here is an example of one I have made should help you to figure it out your error looks to me like you are using the wrong agent as it cant find Visual Studio Code to be able to build the .Net App.
trigger:
branches:
include:
- master
pr: none
pool:
vmImage: vs2017-win2016
variables:
System.Debug: false
azureSubscription: 'AzureSub'
RG: 'myrg'
Location: UK South
appconnectionname: 'azuresub/serviceprinciplename'
jobs:
- job: job1
displayName: Create And Publish Artifact
steps:
- task: UseDotNet#2 ## Not Needed For MS Self Hosted Agent.
displayName: Use .Net Core 5.0.301 SDK
inputs:
packageType: 'sdk'
version: '5.0.301'
- task: DotNetCoreCLI#2
displayName: dotnet restore
inputs:
command: restore
projects: 'Website.csproj'
- task: DotNetCoreCLI#2
displayName: dotnet build
inputs:
projects: 'Website.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet restore unit tests
inputs:
command: restore
projects: 'UnitTests/UnitTests.csproj'
- task: DotNetCoreCLI#2
displayName: dotnet Test
inputs:
command: test
projects: 'UnitTests/UnitTests.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI#2
displayName: dotnet publish
inputs:
command: publish
projects: 'Website.csproj'
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
modifyOutputPath: false
- task: PublishPipelineArtifact#1
displayName: Publish Pipeline Artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'Website'
publishLocation: 'pipeline'
- job: job2
displayName: Create Web App
dependsOn: job1
steps:
# Download Artifact File
- download: none
- task: DownloadPipelineArtifact#2
displayName: 'Download Build Artifacts'
inputs:
patterns: '**/*.zip'
path: '$(Build.ArtifactStagingDirectory)'
# deploy to Azure Web App
- task: AzureWebApp#1
displayName: 'Azure Web App Deploy: nsclassroom'
inputs:
package: $(Build.ArtifactStagingDirectory)/**/*.zip
azureSubscription: $(azureSubscription)
ConnectedServiceName: $(appconnectionname)
appName: 'nsclassroom'
ResourceGroupName: $(RG)
Please put this in a YAML formatter in Azure DevOps to just check spaces or install YML Extension in VS Code.
In the portal I created a seperate Web App and set the service to .Net version 5 instead of Core v3 and was able to build it properly. A new yml file was created and I had to just update the build and publish processes to the path with my csproj.
I think all along I needed the webapp - not devops starter
I have create an empty project on dev.azure.com
I have cloned the repository on my local computer.
I have run this command in the main folder:
$ dotnet new mvc
I have create this azure-pipelines.yml file:
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'artifact2'
I have add, commit and pushed files on dev.azure.com (on master branch)
I have this warning message:
##[warning]Directory 'd:\a\1\a' is empty. Nothing will be added to build artifact 'artifact2'.
I have create a release pipeline but i get an error:
##[error]Error: No package found with specified pattern: D:\a\r1\a\**\*.zip<br/>Check if the package mentioned in the task is published as an artifact in the build or a previous stage and downloaded in the current job.
I do not understand what is wrong in my azure-pipelines.yml for artifact production...
Thanks
It seems that there is an issue where the published dlls are placed. Try the yaml below, that I have explicitly set the output directory for the published dlls and zipped the files after publish(that would probably be your next issue). I have also explicitly set in which folder to look for the published folder in order to publish the artifact.
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI#2
inputs:
command: 'restore'
feedsToUse: 'select'
- task: DotNetCoreCLI#2
inputs:
command: 'build'
- task: DotNetCoreCLI#2
inputs:
command: 'publish'
publishWebProjects: true
modifyOutputPath: true
arguments: '--configuration $(BuildConfiguration) --output "$(build.artifactstagingdirectory)"'
zipAfterPublish: true
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'artifact2'
I'm building a CI-CD azure pipeline with YAML to deploy an azure function app.
Everything works fine, I can even set some properties for the function app, but my function app remains empty.
I downloaded the zip artifact and it looks just fine.
trigger:
- master
variables:
variables:
buildConfiguration: 'Release'
Parameters.RestoreBuildProjects: '**/TestFunction.csproj'
stages:
- stage: Build
jobs:
- job:
pool:
vmImage: 'vs2017-win2016'
continueOnError: false
steps:
- task: DotNetCoreCLI#2
displayName: 'Restore'
inputs:
command: 'restore'
projects: '$(Parameters.RestoreBuildProjects)'
feedsToUse: 'select'
vstsFeed: '/0856b234-f3a6-4052-b5a6-ed9f6ec9c635'
- task: DotNetCoreCLI#2
displayName: Build
inputs:
projects: '$(Parameters.RestoreBuildProjects)'
arguments: '--configuration $(BuildConfiguration)'
- task: DotNetCoreCLI#2
displayName: 'Publish Build'
inputs:
command: publish
arguments: '--configuration $(BuildConfiguration)'
projects: '$(Parameters.RestoreBuildProjects)'
publishWebProjects: false
modifyOutputPath: true
zipAfterPublish: false
- task: ArchiveFiles#2
displayName: "Archive Files"
inputs:
rootFolderOrFile: "$(System.DefaultWorkingDirectory)"
includeRootFolder: false
archiveFile: "$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip"
- task: PublishBuildArtifacts#1
inputs:
PathtoPublish: '$(System.DefaultWorkingDirectory)/build$(Build.BuildId).zip'
ArtifactName: 'drop'
- stage: Deploy
jobs:
# track deployments on the environment
- deployment:
pool:
vmImage: 'vs2017-win2016'
# creates an environment if it doesn’t exist
environment: 'dev'
strategy:
# default deployment strategy
runOnce:
deploy:
steps:
- task: DownloadBuildArtifacts#0
displayName: 'Download Artifacts'
inputs:
buildType: 'current'
downloadType: 'specific'
downloadPath: '$(System.ArtifactsDirectory)'
- task: AzureFunctionApp#1
displayName: 'Azure Function App Deploy: ngproductionfetcherfuncref'
inputs:
azureSubscription: 'Agder Energi Sandbox (1aa9cf92-9d42-49a6-8d31-876ac2dff562)'
appType: functionApp
appName: myFunctionApp
package: '$(System.ArtifactsDirectory)/**/*.zip'
appSettings: '-name0 value0 -name1 value1'
The pipeline is all green:
Got service connection details for Azure App Service:'myFunctionApp'
Updating App Service Application settings. Data: {"WEBSITE_RUN_FROM_PACKAGE":"1"} {"WEBSITE_RUN_FROM_ZIP":{"value":""}}
Updated App Service Application settings and Kudu Application settings.
Package deployment using ZIP Deploy initiated.
Successfully deployed web package to App Service.
Updating App Service Application settings. Data: {"name0":"value0","name1":"value1"} undefined
Updated App Service Application settings and Kudu Application settings.