2

I'm deployng my net core 2.2 app with azure pipeline

yml:

trigger:
- dev

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

steps:
- task: NuGetToolInstaller@1

- task: UseDotNet@2
  displayName: 'Use dotnet sdk 2.2'
  inputs:
    version: 2.x
    includePreviewVersions: false

- 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)'

# code coverage
- task: DotNetCoreCLI@2
  inputs:
    command: test
    projects: '**/*Tests/*.csproj'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'


- script: dotnet -d ef -v migrations script --output $(Build.ArtifactStagingDirectory)\SQL\$(scriptName) --context $(dbContext)  --idempotent --project src\WorkFlowManager.EntityFrameworkCore\WorkFlowManager.EntityFrameworkCore.csproj

- task: PublishBuildArtifacts@1

And now i've added to the solution an azure function project that i want to exclude from the build, because this last project is developed using net core 3.1 .

I'm trying to exclude it from the pipeline with something like that:

variables:
  solution: |
    '**/*.sln'
    '!**/*Project.AzureFunction*.csproj'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Debug'

But the build does not works:

Starting: VSBuild
==============================================================================
Task         : Visual Studio build
Description  : Build with MSBuild and set the Visual Studio version property
Version      : 1.166.0
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build
==============================================================================
##[error]Solution not found using search pattern ''**\*.sln'
'!**\*WorkFlowManager.Functions.EnelGenerator*.csproj'
'.
Finishing: VSBuild

Any ideas?

C1X
  • 665
  • 4
  • 14
  • 25

2 Answers2

2

To exclude the azure function project from build, you can modify your solution file directly to exclude the azure function project.

For below example NUnitTest2.csproj is commented out in the solution file(.sln), and will be excluded when build the solution. You can also check out this thread for other workarounds.

enter image description here

If you do not want to modify the solution file. You can use DotNetCoreCLI@2 task to build all projects except azure function project like below (use ! to exclude a project) .

 - task: DotNetCoreCLI@2
     inputs:
       command: build
       projects: |
         **\*.csproj
         !**\azurefunction.csproj
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
1

The VSBuild@1 task is used for building a VS solution. You could therefore put the new project in a separate solution within the same repository.

Or you could use the DotNetCoreCLI@2 task for your build step that allows you to specify individual projects or a solution to build (see build multiple projects).

Simon Ness
  • 2,272
  • 22
  • 28