JetBrains Space Help

.NET and .NET Core

Prerequisites

  • You have a multiplatform .NET or .NET Core project.

  • If you want to publish artifacts to Space Packages, make sure the project has a NuGet feed.

Eligible images

Build, run tests, and publish in a .NET Core desktop project

Currently, Space Automation does not provide any special API for working with .NET projects. This means, that you should run .NET Core builds by using the dotnet driver directly inside shell scripts.

The content of .space.kts might look like follows:

job(".NET Core desktop. Build, test, publish"){ container(image = "mcr.microsoft.com/dotnet/core/sdk:3.1"){ env["FEED_URL"] = "https://nuget.pkg.jetbrains.space/mycompany/p/pkey/mynuget/v3/index.json" shellScript { content = """ echo Run build... dotnet build echo Run tests... dotnet test ./MainTests/ echo Publish NuGet package... chmod +x publish.sh ./publish.sh """ } } }

In more details:

  • env["FEED_URL"]: specifies a NuGet feed for publishing.

  • dotnet build and dotnet test: runs build and tests correspondingly.

  • ./publish.sh: runs the publishing script. See details below.

The publish.sh script authenticates Automation in the NuGet feed and publishes the NuGet package:

#!/bin/sh echo "Configure credentials" dotnet nuget add source $FEED_URL -n space -u "%JB_SPACE_CLIENT_ID%" -p "%JB_SPACE_CLIENT_SECRET%" --store-password-in-clear-text VERSION=1.0.$JB_SPACE_EXECUTION_NUMBER echo "Publish nuget package" cd dotnet dotnet pack -p:PackageVersion=$VERSION -o ./ dotnet nuget push dotnet-sample.$VERSION.nupkg -s space

In more details:

  • $FEED_URL: specifies feed URL using the environment variable set in .space.kts.

  • $JB_SPACE_CLIENT_ID and $JB_SPACE_CLIENT_SECRET: environment variables that authenticate the Automation service in Space Packages.

  • VERSION="1.0.$JB_SPACE_EXECUTION_NUMBER": uses the $JB_SPACE_EXECUTION_NUMBER to specify the package version based on the script run number.

Last modified: 15 December 2023