Skip to main content

Microsoft Windows application

You can build and test a Microsoft Windows application using a Windows platform on Harness Cloud or a self-hosted Kubernetes cluster build infrastructure.

This guide assumes you've created a Harness CI pipeline. For more information about creating pipelines, go to the CI pipeline creation overview and the Harness Cloud pipeline tutorial.

tip

If you don't have a Harness account yet, you can create one for free at app.harness.io.

Specify architecture

 stages:
- stage:
name: build
identifier: build
type: CI
spec:
cloneCodebase: true
platform:
os: Windows
arch: Amd64
runtime:
type: Cloud
spec: {}

Install dependencies

Harness Cloud runners include pre-installed libraries and tools, and you can use Run steps to install additional dependencies or additional versions. For details about pre-installed tools and versions, go to Platforms and image specifications.

              - step:
type: Run
identifier: dependencies
name: Dependencies
spec:
shell: Powershell
command: |-
dotnet add package Newtonsoft.json --version 12.0.1

Cache dependencies

Add caching to your Build (CI) stage.

Cache your Windows app dependencies with Cache Intelligence. Add caching to your stage.spec and specify the paths to cache:

    - stage:
spec:
caching:
enabled: true
key: cache-{{ checksum "packages.lock.json" }}
paths:
- C:\%LocalAppData%\NuGet\Cache
sharedPaths:
- C:\%LocalAppData%\NuGet\Cache

Build and run tests

Add Run steps to build and run your tests.

              - step:
type: Run
identifier: build_dotnet_app
name: Build DotNet App
spec:
shell: Powershell
command: |-
dotnet restore
dotnet build --no-restore
dotnet test C:\path\to\project.tests.csproj --no-build --verbosity normal
Test Intelligence

For some languages, you can leverage Harness' Test Intelligence feature to reduce unit test time.

Visualize test results

You can view test results on the Tests tab of your pipeline executions. Test results must be in JUnit XML format.

For your pipeline to produce test reports, you need to modify the Run step that runs your tests. Make sure the command generates JUnit XML reports and add the reports specification.

If your test tool doesn't produce JUnit XML formatted reports by default, you can use a converter to output compatible JUnit XML reports, such as NUnit to JUnit or .NET trx2JUnit.

              - step:
type: Run
identifier: install_converter
name: install converter
spec:
shell: Powershell
command: |-
dotnet tool install -g trx2junit
export PATH="C:\Users\USER\.dotnet\tools"
- step:
type: Run
identifier: build_dotnet_app
name: Build DotNet App
spec:
shell: Powershell
command: |-
dotnet restore
dotnet build
dotnet test C:\path\to\project.tests.csproj --no-build --verbosity normal
trx2junit results.trx
reports:
type: JUnit
spec:
paths:
- results.xml

Install Visual Studio

Visual Studio 2019 Enterprise is pre-installed on Hosted Cloud runners. For details about all available tools and versions, go to Platforms and image specifications.

You can use a Run step to install a different version or edition of Visual Studio.

              - step:
type: Run
identifier: install_vs2022
name: install vs2022
spec:
connectorRef: account.harnessImage
image: mcr.microsoft.com/windows/servercore:ltsc2019
shell: Powershell
command: |-
winget install --id Microsoft.VisualStudio.2022.Enterprise

Specify shell

In steps that allow you to supply your own commands, such as Run steps and Background steps, you specify the shell in the step's settings.

              - step:
type: Run
identifier: dotnet restore
name: dotnet restore
spec:
shell: Powershell ## Set to Bash, Powershell, Pwsh (PowerShell Core), Python, or Sh.
command: |- ## Enter your script as you would in a command line shell.
dotnet restore

Several shell binaries are pre-installed on Hosted Cloud runners, including Bash and PowerShell. For details about all available tools and versions, go to Platforms and image specifications.

You can also use Run steps to install different shell tools into the build environment, or specify a container image that has the necessary binaries for the command you want to run.

Setup .NET SDK

For details about building and testing .NET with Harness CI, including how to setup different versions of the .NET SDK, go to the C# (.NET Core) guide.

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.

pipeline:
name: default
identifier: default
projectIdentifier: default
orgIdentifier: default
tags: {}
properties:
ci:
codebase:
connectorRef: YOUR_CODE_REPO_CONNECTOR_ID
repoName: YOUR_REPO_NAME
build: <+input>
stages:
- stage:
name: build and test
identifier: build_and_test
type: CI
spec:
cloneCodebase: true
caching:
enabled: true
key: cache-{{ checksum "packages.lock.json" }}
paths:
- C:\%LocalAppData%\NuGet\Cache
execution:
steps:
- step:
type: Run
identifier: dependencies
name: Dependencies
spec:
shell: Powershell
command: |-
dotnet add package Newtonsoft.json --version 12.0.1
- step:
type: Run
identifier: install_converter
name: install converter
spec:
shell: Powershell
command: |-
dotnet tool install -g trx2junit
export PATH="C:\Users\USER\.dotnet\tools"
- step:
type: Run
identifier: build_dotnet_app
name: Build DotNet App
spec:
shell: Powershell
command: |-
dotnet restore
dotnet build
dotnet test C:\path\to\project.tests.csproj --no-build --verbosity normal
trx2junit results.trx
reports:
type: JUnit
spec:
paths:
- results.xml
sharedPaths:
- C:\%LocalAppData%\NuGet\Cache
platform:
os: Windows
arch: Amd64
runtime:
type: Cloud
spec: {}

Next steps

Now that you have created a pipeline that builds and tests a Windows app, you could: