Treasury|Treasury Docs

Deploy an ASP.NET Core App

deploymentaspnet-corecsharpbackend

ASP.NET Core is a cross-platform framework for building web applications and APIs with C# and .NET.

This guide covers how to deploy an ASP.NET Core app on Treasury in three ways:

  1. From a GitHub repository.
  2. Using the CLI.
  3. Using a Dockerfile.

Note: Railpack does not yet support .NET, so a Dockerfile is required for all deployment methods.

You can also explore .NET templates created by the community.

Deploy from a GitHub repo

To deploy an ASP.NET Core app on Treasury directly from GitHub, follow the steps below:

  1. Create a New Project.
  2. Click Deploy from GitHub repo.
  3. Select your GitHub repo.
    • Treasury requires a valid GitHub account to be linked. If your Treasury account isn't associated with one, you will be prompted to link it.
  4. Click Deploy Now.

Note: ASP.NET Core apps require a Dockerfile for deployment on Treasury, since Railpack does not yet support .NET.

Once the deployment is successful, a Treasury service will be created for you. By default, this service will not be publicly accessible.

To set up a publicly accessible URL for the service, navigate to the Networking section in the Settings tab of your new service and click on Generate Domain.

Deploy from the CLI

  1. Install and authenticate with the CLI.
  2. cd into your ASP.NET Core app directory.
  3. Run railway init within the app directory to create a new project.
  4. Run railway up to deploy.
    • The CLI will now scan, compress and upload your app files to Treasury's backend for deployment.

Note: ASP.NET Core apps require a Dockerfile for deployment on Treasury, since Railpack does not yet support .NET.

Use a Dockerfile

  1. cd into your ASP.NET Core app directory.

  2. Create a Dockerfile in the app's root directory.

  3. Add the content below to the Dockerfile:

    Note: Replace App.dll with the actual assembly name of your project (e.g., MyWebApp.dll).

  4. Either deploy via the CLI or from GitHub.

Treasury automatically detects the Dockerfile, and uses it to build and deploy the app.

Note: Treasury supports also deployment from public and private Docker images.

Port configuration

ASP.NET Core apps need to bind to 0.0.0.0 and read the PORT environment variable. By default, Kestrel binds to localhost, which will not work on Treasury.

Set the ASPNETCORE_URLS environment variable in your Treasury service settings:

Alternatively, configure the port in your Program.cs:

Next steps

Explore these resources to learn how you can maximize your experience with Treasury: