C# .NET

Learn how to get started with C# .NET in Codesphere.

December 14, 2023 2 Min Read
C# .NET
C# .NET

Codesphere

From everyone in the Codesphere Team:)

C# can be installed in Codesphere using the Nix Package Manager. In this guide you get an Introduction in how C# can be used in Codesphere.

Example Applications

Beginner friendly C# App

Installation of .NET SDK

To manually install the .NET SDK simply run this command to install the .NET SDK to your local Nix Store.

nix-env -iA nixpkgs.dotnet-sdk

Crucial Configuration Settings for .NET Applications on Codesphere

To run .NET applications on Codesphere, it's crucial to configure them to listen on port 3000 for external access. You can set this in the launchSettings.json of your project like this:

{
  "profiles": {
    "YourAppName": {
      "commandName": "Project",
      "applicationUrl": "http://localhost:3000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

This ensures your app binds to port 3000 and is accessible via Codesphere's network, aligning with its expected configuration for web applications.

Run Applications

Builing a .NET Application

Once you have the .NET SDK installed using nix-env -iA nixpkgs.dotnet-sdk, you can start building your .NET projects.

To build a project, navigate to the project folder and run:

dotnet build

This compiles your code into assemblies and prepares the project for execution. The output is typically located in the /bin/Debug or /bin/Release folder, depending on the build configuration.

You can specify a configuration (Debug or Release) during the build process:

dotnet build --configuration Release 

or 

dotnet build --configuration Debug

Test Application

To run Unit Tests of your .NET Application run the following command:

dotnet test

Run Application

To Run .NET Applications on Codesphere make sure your Application listens on Port 3000. The port the Application is listening on is defined in the

After you start your application with the following command.

dotnet run

This will build your app by default in Debug Configuration and runs the app.

After the Startup of the Application the application is reachable under the URL of the workspace.

If you want to do this step automatically add this command to you CI Pipeline under the run Stage.

Codesphere CI

Setup CI for C# .NET

To persist the .NET SDK Installation even if you change your workspace settings or move your programm to another workspace we have to setup the CI Prepare Stage.

Prepare Stage

Add a step in the prepare stage of your CI that runs the following Command:

nix-env -iA nixpkgs.dotnet-sdk

Also the build of the Application can also be done in the prepare stage by adding the dotnet build command to the prepare stage as another step.

Test Stage

In the Test Stage of the CI you can run your Unit Tests automatically. Just add an step for the command.

dotnet test
Run Stage

To run your application by the CI add the commands from the .NET SDK that will run the application. This will ensure your application starts automatic if you change settings regarding your workspace or you are updating your plan.

About the Author

C# .NET

Codesphere

From everyone in the Codesphere Team:)

We are building the next generation of Cloud, combining Infrastructure and IDE in one place, enabling a seamless DevEx and eliminating the need for DevOps specialists.

More Posts

Deploying Landscapes on Codesphere

Deploying Landscapes on Codesphere

Learn how to deploy and run multiple services that can independently scale vertically and horizontally within a single workspace. Suitable for hosting entire application landscapes.

Monitoring & Alerting

Monitoring & Alerting

Learn how to access Codesphere's built in resource monitoring and check the uptime of your applications.

Path-Based Routing

Path-Based Routing

Learn how to connect multiple independent applications to a single domain by associating different paths with distinct workspaces