0
votes

I have created a C# Console App and a C# Unit Test by following this Microsoft Article here:

https://docs.microsoft.com/en-us/visualstudio/test/walkthrough-creating-and-running-unit-tests-for-managed-code?view=vs-2019

This works fine within Visual Studio.

I now want to create an Azure DevOps Pipeline and want it to call this Unit Test as part of the Pipeline. I have added the VsTest Test Assemblies to the Pipeline but I do not know how to make sure that this is actually running the unit test (like when I see it running within Visual Studio).

When I check the results of the build, I can see it has passed all the tests but even though this is marked as passed, there's an error reading:

"Error: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."

I know this is connected to the version of .Net Core that is being used, but I don't know where in my Pipeline I need to change this?

1
Can you add your csproj file?Krzysztof Madej
And your pipeline if you could?Krzysztof Madej
Here's the csproj file for the main app: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> </Project>BGCollector
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <IsPackable>false</IsPackable> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> <PackageReference Include="MSTest.TestAdapter" Version="2.1.0" /> <PackageReference Include="MSTest.TestFramework" Version="2.1.0" /> <PackageReference Include="coverlet.collector" Version="1.2.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Bank\Bank.csproj" /> </ItemGroup> </Project>BGCollector
The csproj above is the one for the unit testBGCollector

1 Answers

0
votes

In order to select the version of .NET Core you want to use, you can use the Use .NET Core task. In YAML code, within a job, I specify the aforementioned task the following way:

- task: UseDotNet@2
  displayName: 'Use .NET Core SDK $(dotnetSdkVersion)'
  inputs:
    packageType: sdk
    version: $(dotnetSdkVersion)

In the beginning of the YAML file, you would have to set the dotnetSdkVersion variable that I am using here. You can do it the following way, to set it for .NET Core 3.1.201:

variables:
  dotnetSdkVersion: '3.1.201'