How to create a C# / dotnet 8 Replit Instance

Date: 2024-04-19 | create | tech | csharp | dotnet | replit |

In this post we're going to create a C# Replit instance running dotnet 8.

Just want to start coding with C# / dotnet 8? Fork my C# / dotnet 8 Replit

Create a Replit w C# / Dotnet 8

Replit allows several configuration options for your instance. At time of writing, the official C# Replit template runs on dotnet 6 so we gotta change it to allow for dotnet 8.

For an in-depth description of the Replit configuration options: How to create an F# / dotnet 8 Replit Instance

The .replit file configures how the Replit instance will run.

run = ["dotnet", "run"]
entrypoint = "main.cs"

hidden = ["bin", "obj"]

[env]
DOTNET_NOLOGO = "1"
DOTNET_CLI_TELEMETRY_OPTOUT = "1"
DOTNET_CLI_HOME = "$XDG_CACHE_HOME"

[gitHubImport]
requiredFiles = [".replit", "replit.nix"]

[nix]
channel = "stable-23_11"

The replit.nix file configures what dependencies to load in our instance.

{ pkgs }: {
    deps = [
        pkgs.dotnet-sdk_8
    ];
}

Now our instance is setup to include the dotnet 8 SDK but we need to actually use that in our project.

*.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp8.0</TargetFramework>
    <StartupObject>Program</StartupObject>
  </PropertyGroup>

</Project>

Now we can run our C# program with dotnet 8.

main.cs

using System;

class Program {
  public static void Main (string[] args) {
    Console.WriteLine ("Hello World");
  }
}

Next

I've reached out to Replit on X and created a support forum ticket to try and get the official F# and C# templates updated to dotnet 8. Please go vote for those so we can get them prioritized!

If you liked this post you might also like:

Want more like this?

The best / easiest way to support my work is by subscribing for future updates and sharing with your network.