Skip to content

Support single file cs apphost #9612

@davidfowl

Description

@davidfowl

The .NET 10 SDK supports single file C# programs. This would allow us to run aspire applications as a single cs file instead of using a project. We have lots of configuration options spread across appsettings and the launch profile that need to go somewhere.

Proposal work to make this experience nice:

  • We need to support this via aspire run. It's unclear how this will interact with scanning.
  • We need to find a home for these settings.
  • We need single file apphost templates.
  • We need a way to add a single file as project as an aspire resource (see AddCSharpApp below) (with debug support?)

Current POC: ()

#:package Aspire.Hosting.AppHost@9.3.0
// This is because the current version does not support NuGet based MSBuild SDKs
#:package Aspire.Hosting.Orchestration.win-x64@9.3.0
#:package Aspire.Dashboard.Sdk.win-x64@9.3.0

#region config
Environment.SetEnvironmentVariable("ASPIRE_ALLOW_UNSECURED_TRANSPORT", "true");
Environment.SetEnvironmentVariable("ASPNETCORE_URLS", "http://localhost:5003");
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
Environment.SetEnvironmentVariable("ASPIRE_DASHBOARD_OTLP_ENDPOINT_URL", "http://localhost:4317");
Environment.SetEnvironmentVariable("ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL", "http://localhost:5001");

Environment.SetEnvironmentVariable("Logging__LogLevel__Default", "Information");
Environment.SetEnvironmentVariable("Logging__LogLevel__Aspire.Hosting.Dcp", "Warning");
Environment.SetEnvironmentVariable("Logging__LogLevel__Microsoft.AspNetCore", "Warning");
#endregion

var builder = DistributedApplication.CreateBuilder(args);

builder.AddCSharpApp("api", "api.cs")
       .WithHttpEndpoint(targetPort: 5000);

builder.Build().Run();

#region csharpfile
public static class CSFileExtensions
{
    public static IResourceBuilder<CsharpFileApp> AddCSharpApp(this IDistributedApplicationBuilder builder, string name, string filePath)
    {
        return builder.AddResource(new CsharpFileApp(name, Environment.CurrentDirectory))
            .WithArgs("run", filePath);
    }
}

public class CsharpFileApp(string name, string workingDirectory) : ExecutableResource(name, "dotnet", workingDirectory)
{

}
#endregion

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-app-modelIssues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions