0

We have a Visual Studio solution containing multiple projects. Till now, they have all been in C#. However, we decided:

  1. We want to add performance testing;
  2. We want to use k6 as the performance testing tool;
  3. We want to write the tests in TypeScript; and
  4. The performance tests should live in the same repo and preferably the same solution as what it is testing.

Locally, I've successfully created a TypeScript project in Visual Studio 2022 within the Visual Studio solution we wish to test. While I don't know how to execute these tests from Visual Studio itself instead of the command line, I don't presently care about that.

I've pushed the performance tests to our Azure DevOps repo and created a pull request. In order to complete the PR and merge to master, the build must succeed, and this is where I am presently stuck.

I've added 'Install Node.js' and 'Install TypeScript' to the azure-pipelines.yml and those tasks appear to work, but ultimately the build jobs fail.

My yaml file currently looks like this:

# 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://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

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

jobs:
- job: buildServer
  pool:
    vmImage: 'windows-2022'
  steps:
    - task: NodeTool@0
      displayName: 'Install Node.js'
      inputs:
        versionSpec: 16.x
    - script: npm install --save-dev typescript
      displayName: 'Install TypeScript'

    - task: UseDotNet@2
      displayName: 'Install .NET 6 SDK'
      inputs:
        packageType: 'sdk'
        version: '6.0.x'
        performMultiLevelLookup: true

    - task: DotNetCoreCLI@2
      displayName: 'dotnet restore'
      inputs:
        command: 'restore'
        feedsToUse: 'config'
        nugetConfigPath: 'NuGet.config'
        verbosityRestore: 'Normal'

    - 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:
        testSelector: 'testAssemblies'
        testAssemblyVer2: |
          **\bin\$(BuildConfiguration)\**\Enpal.SalesforceCache.Test.dll
          !**\xunit.runner.visualstudio.testadapter.dll
          !**\xunit.runner.visualstudio.dotnetcore.testadapter.dll
        searchFolder: '$(System.DefaultWorkingDirectory)'
        runTestsInIsolation: true
        codeCoverageEnabled: true

    - task: PublishTestResults@2
      inputs:
        testResultsFormat: 'XUnit'
        testResultsFiles: '**/TEST-*.xml'
        searchFolder: '$(Agent.TempDirectory)\TestResults'

    - task: ArchiveFiles@2
      inputs:
        rootFolderOrFile: '$(Build.BinariesDirectory)'
        includeRootFolder: true
        archiveType: 'zip'
        archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
        replaceExistingArchive: true

    - task: PublishBuildArtifacts@1
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'

- job: buildAndPushClientNuget
  pool:
    vmImage: 'windows-2022'
  steps:
  - task: NodeTool@0
    displayName: 'Install Node.js'
    inputs:
      versionSpec: 16.x
  - script: npm install --save-dev typescript
    displayName: 'Install TypeScript'

  - task: UseDotNet@2
    displayName: 'Install .NET 6 SDK'
    inputs:
      packageType: 'sdk'
      version: '6.0.x'
      performMultiLevelLookup: true

  - task: NuGetToolInstaller@1

  - task: DotNetCoreCLI@2
    displayName: 'dotnet restore'
    inputs:
      command: 'restore'
      feedsToUse: 'config'
      nugetConfigPath: 'NuGet.config'
      verbosityRestore: 'Normal'

  # Build nuget
  - task: DotNetCoreCLI@2
    displayName: 'dotnet pack'
    inputs:
      command: 'custom'
      custom: 'pack'
      arguments: '-c $(buildConfiguration) -o $(Build.ArtifactStagingDirectory) -p:Build=$(Build.BuildId) --include-symbols'

  # publish artifacts
  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'drop'
      publishLocation: 'Container'

  # Publish nuget
  - task: NuGetCommand@2
    condition: ne(variables['Build.Reason'], 'PullRequest')
    inputs:
      command: 'push'
      packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
      nuGetFeedType: 'internal'
      publishVstsFeed: 'enpal'

  # Publish symbols
  - task: PublishSymbols@2
    condition: ne(variables['Build.Reason'], 'PullRequest')
    inputs:
      SearchPattern: '**/bin/**/*.pdb'
      SymbolServerType: 'TeamServices'
      DetailedLog: false

The buildServer/VSBuild task fails with:

"D:\a\1\s\SalesforceCache.sln" (default target) (1) ->
"D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj" (default target) (6) ->
(ResolveAssemblyReferences target) -> 
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277: Found conflicts between different versions of "Microsoft.AspNetCore.Mvc.Core" that could not be resolved. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277: There was a conflict between "Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" and "Microsoft.AspNetCore.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:     "Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was chosen because it was primary and "Microsoft.AspNetCore.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was not. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:     References which depend on "Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" [C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll]. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:         C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:           Project file item includes which caused reference "C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll". [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:             C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:     References which depend on "Microsoft.AspNetCore.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" []. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:         D:\a\1\s\Enpal.SalesforceCache.Client\bin\Release\net6.0\Enpal.SalesforceCache.Client.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:           Project file item includes which caused reference "D:\a\1\s\Enpal.SalesforceCache.Client\bin\Release\net6.0\Enpal.SalesforceCache.Client.dll". [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:             D:\a\1\s\Enpal.SalesforceCache.Client\bin\Release\net6.0\Enpal.SalesforceCache.Client.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]


"D:\a\1\s\SalesforceCache.sln" (default target) (1) ->
"D:\a\1\s\SalesforceCache.PerformanceTest\SalesforceCache.PerformanceTest.njsproj" (default target) (8) ->
(CoreCompile target) -> 
  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\Node.js Tools\Microsoft.NodejsToolsV2.targets(64,5): error : TypeScript compiler is not installed. Please execute 'npm install --save-dev typescript' [D:\a\1\s\SalesforceCache.PerformanceTest\SalesforceCache.PerformanceTest.njsproj]

    560 Warning(s)
    1 Error(s)

Time Elapsed 00:00:45.57
##[error]Process 'msbuild.exe' exited with code '1'.
Finishing: VSBuild

You'll note 'npm install --save-dev typescript' has already been executed in the earlier script and that succeeded.

Then buildAndPushClientNuget/dotnet pack fails with:

  Successfully created package 'D:\a\1\a\Enpal.SalesforceCache.Client.1.0.0.51800.nupkg'.
  Successfully created package 'D:\a\1\a\Enpal.SalesforceCache.Client.1.0.0.51800.symbols.nupkg'.
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277: Found conflicts between different versions of "Microsoft.AspNetCore.Mvc.Core" that could not be resolved. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277: There was a conflict between "Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" and "Microsoft.AspNetCore.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:     "Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was chosen because it was primary and "Microsoft.AspNetCore.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" was not. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:     References which depend on "Microsoft.AspNetCore.Mvc.Core, Version=2.2.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" [C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll]. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:         C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:           Project file item includes which caused reference "C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll". [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:             C:\Users\VssAdministrator\.nuget\packages\microsoft.aspnetcore.mvc.core\2.2.5\lib\netstandard2.0\Microsoft.AspNetCore.Mvc.Core.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:     References which depend on "Microsoft.AspNetCore.Mvc.Core, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60" []. [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:         D:\a\1\s\Enpal.SalesforceCache.Client\bin\Release\net6.0\Enpal.SalesforceCache.Client.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:           Project file item includes which caused reference "D:\a\1\s\Enpal.SalesforceCache.Client\bin\Release\net6.0\Enpal.SalesforceCache.Client.dll". [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
C:\hostedtoolcache\windows\dotnet\sdk\6.0.402\Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3277:             D:\a\1\s\Enpal.SalesforceCache.Client\bin\Release\net6.0\Enpal.SalesforceCache.Client.dll [D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\Enpal.SalesforceCache.Client.AspNet.csproj]
  Enpal.SalesforceCache.Client.AspNet -> D:\a\1\s\Enpal.SalesforceCache.Client.AspNet\bin\Release\net6.0\Enpal.SalesforceCache.Client.AspNet.dll
  Successfully created package 'D:\a\1\a\Enpal.SalesforceCache.Client.AspNet.1.0.0.51800.nupkg'.
  Successfully created package 'D:\a\1\a\Enpal.SalesforceCache.Client.AspNet.1.0.0.51800.symbols.nupkg'.
  Enpal.SalesforceCache.Client.Helper -> D:\a\1\s\Enpal.SalesforceCache.Client.Helper\bin\Release\net6.0\Enpal.SalesforceCache.Client.Helper.dll
  Successfully created package 'D:\a\1\a\Enpal.SalesforceCache.Client.Helper.1.0.0.51800.nupkg'.
  Successfully created package 'D:\a\1\a\Enpal.SalesforceCache.Client.Helper.1.0.0.51800.symbols.nupkg'.
##[error]Error: The process 'C:\hostedtoolcache\windows\dotnet\dotnet.exe' failed with exit code 1
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
##[error]Dotnet command failed with non-zero exit code on the following projects : 
Finishing: dotnet pack

No idea what to make of it, but the warnings precede adding k6 and while annoying and it would be great to get rid of them, they seem harmless.

How can I fix the pipeline so the build will succeed?

(Actually executing the tests as part of my build process is still an open concern, but I'm not necessarily looking for that answer here.)

Brian Kessler
  • 2,187
  • 6
  • 28
  • 58
  • Can you build successfully locally? If you can build successfully locally, you can use the local machine as a self-hosted agent, and then use this self-hosted agent to run the pipeline to see if you can build successfully. – Ziyang Liu-MSFT Nov 03 '22 at 09:08
  • @ZiyangLiu-MSFT, thanks for response. I've no idea how to execute the pipeline locally. Anyway, I figured out the problem and a working (though less than ideal) solution which I'll document as an answer (which I won't accept) later. – Brian Kessler Nov 03 '22 at 10:23

1 Answers1

0

I'm sure there is a better way to solve the problem (so I'm not going to accept my own answer here), but if anyone is interested (and perhaps can tell me how to improve the solution), I'll leave this here:

The problem is that when Azure DevOps attempts to process the above azure-pipelines.yml, it includes all the projects which have been included in the solution.

The dirty fix is to just remove the TypeScript project from the solution while leaving all the files in place. A better fix (which I don't know how to do) would be to tell the system to ignore the TypeScript project or (alternatively, but more annoyingly) whitelist the projects we actually want.

Once we removed the project, we are also able to remove the node task and typescript script from the above yaml.

Afterwards, we were then able to add this third job to deal with the TypeScript:

- job: buildAndPushK6
  pool:
    vmImage: 'ubuntu-latest'
  steps:    
    - task: NodeTool@0
      displayName: 'Install Node.js'
      inputs:
        versionSpec: 16.x

    - script: yarn install
      workingDirectory: 'SalesforceCache.PerformanceTest'
      displayName: 'yarn install'

    - script: yarn webpack
      workingDirectory: 'SalesforceCache.PerformanceTest'

    - task: PublishBuildArtifacts@1
      displayName: 'publish artifact'
      condition: ne(variables['Build.Reason'], 'PullRequest')
      inputs:
        pathToPublish: SalesforceCache.PerformanceTest/dist
        artifactName: k6_artifact

It did not matter that this was no longer a project.

Brian Kessler
  • 2,187
  • 6
  • 28
  • 58
  • 1
    When you use the "VSBuild@1" task, you can specify the projects you want to build in the "Solution" instead of specifying the entire solution. For more info, please refer to [Visual Studio Build task Arguments](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/build/visual-studio-build?view=azure-devops#arguments) – Ziyang Liu-MSFT Nov 18 '22 at 01:34
  • @ZiyangLiu-MSFT, Cheers for the response. The solution has a lot of projects and we only want to ignore one. Is there some way to blacklist instead of whitelist? I don't see it. – Brian Kessler Nov 18 '22 at 10:32
  • 1
    VSBuild task does not support blacklist projects. This task calls msbuild.exe to build and build solution will build all projects in it, which is the default behavior. To exclude projects to build in pipeline, you can also exclude projects from solution configuration (Not recommended) or create a new configuration that excludes specific projects (Recommended). You can refer to [this ticket](https://stackoverflow.com/questions/64138051/exclude-projects-from-azure-build-pipeline) for detailed explanation and information. – Ziyang Liu-MSFT Nov 21 '22 at 08:30