C# (.NET Core)
Use a CI pipeline to build and test a C# (.NET Core) application.
You can build and test a C# and .NET Core application using a Linux or Windows platform on Harness Cloud or a self-managed Kubernetes cluster build infrastructure.
This guide assumes you've created a Harness CI pipeline.
Specify architecture
You can use a Linux or Windows platform to build and test C# (.NET Core) apps. These examples use Linux build infrastructure.
stages:
- stage:
name: build
identifier: build
type: CI
spec:
cloneCodebase: true
platform:
os: Linux
arch: Amd64 ## Can be Amd64 or Arm64
runtime:
type: Cloud
spec: {}There are several self-managed build infrastructure options. This example uses a Kubernetes cluster build infrastructure.
stages:
- stage:
name: build
identifier: build
description: ""
type: CI
spec:
cloneCodebase: true
infrastructure:
type: KubernetesDirect
spec:
connectorRef: YOUR_KUBERNETES_CLUSTER_CONNECTOR_ID
namespace: YOUR_NAMESPACE
automountServiceAccountToken: true
nodeSelector: {}
os: LinuxInstall dependencies
The .NET Core SDK and other .NET libraries are pre-installed on Harness Cloud runners. For details about all available tools and versions, go to Platforms and image specifications. You can use Run steps to install additional dependencies or run dotnet restore.
You can use Run steps to install dependencies or run commands such as dotnet restore.
Cache dependencies
Add caching to your Build (CI) stage.
Cache your .NET dependencies with Cache Intelligence.
Add caching to your stage.spec:
You can use built-in steps to:
Build and run tests
Add Run steps to build and run your tests.
Visualize test results
You can view test results on the Tests tab of your pipeline executions. Harness supports JUnit XML and TRX test report formats.
For .NET projects, you can generate TRX reports natively using dotnet test -l:trx without needing a converter. Alternatively, you can use a converter to output JUnit XML reports, such as NUnit to JUnit or .NET trx2JUnit.
For your pipeline to produce test reports, you need to modify the Run step that runs your tests. Make sure the command generates test reports and add the reports specification.
Run tests with Test Intelligence
Test Intelligence is available for C# (.NET Core); however, it is behind the feature flag TI_DOTNET. Contact Harness Support to enable the feature.
With this feature flag enabled, you can use Run Tests steps to run unit tests with Test Intelligence on C# codebases.
Test splitting
Harness CI supports test splitting (parallelism) for both Run and Run Tests steps.
Specify version
The .NET SDK is pre-installed on Hosted Cloud runners. For details about all available tools and versions, go to Platforms and image specifications.
If you need a specific .NET Core SDK version that isn't already installed, you can use a Run step to install it.
Specify the desired .NET SDK image tag in your steps. There is no need for a separate install step when using Docker.
Full pipeline examples
The following full pipeline examples are based on the partial examples above.
If you copy this example, replace the placeholder values with appropriate values for your code repo connector and repository name. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.
If you copy this example, replace the placeholder values with appropriate values for your code repo connector, Kubernetes cluster connector, Kubernetes namespace, and repository name. Depending on your project and organization, you may also need to replace projectIdentifier and orgIdentifier.
Next steps
Now that you have created a pipeline that builds and tests a C# (.NET Core) app, you could:
Create triggers to automatically run your pipeline.
Add steps to build and upload artifacts.
Add a step to build and push an image to a Docker registry.
Last updated
Was this helpful?