> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C#/.NET Core

> Upsun Cloud supports deploying .NET applications by allowing developers to define a build process and pass its variables to the .NET Core build environment.


> [!TIP]
>
> You can now use composable image to install runtimes and tools in your application container. To find out more, see the [Composable image](https://developer.upsun.com/docs/configure-apps/app-reference/composable-image.md) topic.

## Supported versions

You can select the major and minor version.

Patch versions are applied periodically for bug fixes and other maintenance updates. By default, you get the latest available patches each time you deploy. If your project has a [maintenance window](https://developer.upsun.com/docs/core-concepts/build-deploy.md#maintenance-window) configured, Upsun Cloud applies patches only during that window. Upsun Cloud may still apply urgent or critical fixes outside of the maintenance window.

* 10.0
* 8.0

## Deprecated versions

The following versions are still available in your projects,
but they're at their end of life and are no longer receiving security updates from upstream.

*No deprecated versions.*

To ensure your project remains stable in the future, switch to a [supported version](#supported-versions).

## Retired versions

The following versions have been retired and are no longer available.
If your project uses a retired version, you must update to a [supported version](#supported-versions).

* 7.0
* 6.0
* 5.0
* 3.1
* 2.2
* 2.1
* 2.0

### Specify the language

To use .Net Core, specify `dotnet` as your [app's `type`](https://developer.upsun.com/docs/configure-apps/app-reference/single-runtime-image#type):


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     \<APP\_NAME>:
&#x20;       type: 'dotnet:\<VERSION\_NUMBER>'
&#x20;&#x20;

For example:


&#x20;   applications:
&#x20;     \# The app's name, which must be unique within the project.
&#x20;     myapp:
&#x20;       type: 'dotnet:\{\{version:dotnet:latest}}'

## Building the application

To build basic applications in .NET containers, it's enough to use the [`dotnet publish` command](https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish)
with the default [framework-dependent deployment](https://docs.microsoft.com/en-us/dotnet/core/deploying/#publish-framework-dependent):


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'dotnet:\{\{version:dotnet:latest}}'
&#x20;       hooks:
&#x20;         build: |
&#x20;           set -xe
&#x20;           dotnet publish --output "\$PLATFORM\_OUTPUT\_DIR" \\
&#x20;             -p:UseRazorBuildServer=false \\
&#x20;             -p:UseSharedCompilation=false

where `PLATFORM_OUTPUT_DIR` is the output directory for compiled languages available at build time.

Typically, .NET Core builds start a collection of build servers, which are helpful for repeated builds.
On Upsun Cloud, however, if this process isn't disabled,
the build process doesn't finish until the idle timeout is reached.

As a result, you should include `-p` toggles that disable the Razor compiler for dynamic CSHTML pages (`UseRazorBuildServer`)
and the .NET MSBuild compiler (`UseSharedCompilation`).

If you want multiple builds for your application,
make sure to call `dotnet build-server shutdown` at the end of your build hook.

## Running the application

.NET Core applications should be started using the `web.commands.start` directive in `.upsun/config.yaml`.
This ensures that the command starts at the right moment and stops gracefully when a redeployment needs to be executed.
Also, should the program terminate for any reason, it's automatically restarted.
Note that the start command *must* run in the foreground.

Incoming requests are passed to the application using either a TCP (default) or Unix socket.
The application must use the [appropriate environment variable](https://developer.upsun.com/docs/configure-apps/image-properties/web.md#where-to-listen) to determine the URI to listen on.
For a TCP socket ([recommended](https://go.microsoft.com/fwlink/?linkid=874850)), the application must listen on `http://127.0.0.1`,
using the `PORT` environment variable.

There is an Nginx server sitting in front of your application.
Serving static content via Nginx is recommended, as this allows you to control headers (including cache headers)
and also has marginal performance benefits.

Note that HTTPS is also terminated at the Nginx proxy,
so the `app.UseHttpsRedirection();` line in `Startup.cs` should be removed.
To force HTTPS-only, refer to the [routes documentation](https://developer.upsun.com/docs/routes/https.md#enable-https).

The following example configures an environment to serve the static content folders commonly found in [ASP.NET MVC](https://dotnet.microsoft.com/apps/aspnet/mvc) templates using Nginx,
while routing other traffic to the .NET application.


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'dotnet:\{\{version:dotnet:latest}}'
&#x20;       web:
&#x20;         locations:
&#x20;           "/":
&#x20;             root: "wwwroot"
&#x20;             allow: true
&#x20;             passthru: true
&#x20;             rules:
&#x20;               \# Serve these common asset types with customs cache headers.
&#x20;               \\.(jpe?g|png|gif|svgz?|css|js|map|ico|bmp|eot|woff2?|otf|ttf)\$:
&#x20;                 allow: true
&#x20;                 expires: 300s
&#x20;         commands:
&#x20;             start: "dotnet WebApplication1.dll"

You can also route all requests to the application unconditionally:


&#x20;   applications:
&#x20;     myapp:
&#x20;       type: 'dotnet:\{\{version:dotnet:latest}}'
&#x20;       web:
&#x20;         locations:
&#x20;           "/":
&#x20;             allow: false
&#x20;             passthru: true

&#x20;         commands:
&#x20;           start: "dotnet WebApplication1.dll"

> [!NOTE]
>
> To deploy a .NET Core project, create a new project from the
> [Upsun Console](https://console.upsun.com/projects/create-project)
> and select a template, or push your existing code.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.