How to build Fake Assembies in Azure pipeline

197 Views Asked by At

introduction:

I have a project in C# that has also related Unit Tests project. It uses Microsoft's Unit Test framework as well as its technology to creates Fakes. It works well locally - I am able to build project and run unit tests.

problem:

Now I try to add pipeline on dev.azure.com and I am getting an warnings like:

Primary reference "___.Fakes". ##[warning]C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(2352,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "___.Fakes". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

and errors like:

##[error]___\___Tests\___Tests.cs(9,43): Error CS0234: The type or namespace name 'Fakes' does not exist in the namespace 'Microsoft.AspNetCore.SignalR.Client' (are you missing an assembly reference?)

etc.

what I have already done:

  • I put Microsoft.VisualStudio.TestPlatform.TestFramework.dll and Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll as Solution item and reference it manually browsing as read that these dlls are not available in NuGETs.
  • I have turned off the IntelliTrace in MSBuild Arguments /p:EnableIntelliTrace=false

question

  • How to make this pipeline working? So how to create Fakes assemblies during pipeline build on Azure?
1

There are 1 best solutions below

0
SiddheshDesai On

Instead of explicitly referencing certain DLLs, try using NuGet packages. This can help guarantee that all required dependencies are resolved appropriately during the build process. You stated manually referencing "Microsoft.VisualStudio.TestPlatform.TestFramework.dll" and "Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll." And build your project locally and then Push it in Azure DevOps repository. These should be available through NuGet packages in most cases.

Make sure you check your csproj files and all the references are correctly added there:-

enter image description here

Make sure you refer this Unit Test Run tutorial to run your Unit Tests successfully in Azure DevOps pipeline:-

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:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: '$(System.DefaultWorkingDirectory)'
- task: VSTest@2
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: '$(System.DefaultWorkingDirectory)/<test-files-dlls>'
    searchFolder: '$(System.DefaultWorkingDirectory)'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: 'Run unit tests - $(buildConfiguration)'
  inputs:
    command: 'test'
    projects: '**/*.csproj'
    arguments: '--no-build --configuration $(buildConfiguration)'

Output:-

enter image description here

Test Run was successful in Azure Test Plan tab like below:-

enter image description here