Skip to content

aspire update needs fallback parsing for single file projects #12196

@mitchdenny

Description

@mitchdenny

Currently if the apphost.cs file in a single-file aspire project gets into a bad state (e.g. the SDK cannot be resolved) then the command to resolve the list of properties and items (dotnet build -getItem:PackageReference ...etc) will fail to run.

For *.csproj based app host projects we have a FallbackProjectParser which attempts to compensate for the issue by reading the XML file directly to try and "heal the project".

Obviously the XML based parser will not work with the single-file apphost.cs.

We need to enhance the logic in FallbackProjectParser so that it can extract the same JsonDocument structure from structure of the apphost.cs file.

Take the existing implementation of ParseProject and put it into another private method called ParseCsprojProjectFile and implement a new method called ParseCsAppHostFile and implement regular expressions which will extract the #:sdk directive and the #:package directive from an apphost.cs file and insert that information into a JSON payload that our processing logic expects.

Here is an example of a project that is a torn-state:

#:sdk Aspire.AppHost.Sdk@13.0.0-preview.1.25519.5
#:package Aspire.Hosting.NodeJs@9.5.1
#:package Aspire.Hosting.Python@9.5.1
#:package Aspire.Hosting.Redis@9.5.1
#:package CommunityToolkit.Aspire.Hosting.NodeJS.Extensions@9.8.0

#pragma warning disable ASPIREHOSTINGPYTHON001

var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("cache");

var apiService = builder.AddPythonScript("apiservice", "./api_service", "app.py")
    .WithUvEnvironment()
    .WithReference(cache)
    .WithHttpEndpoint(env: "PORT")
    .WithExternalHttpEndpoints()
    .PublishAsDockerFile(c =>
    {
        c.WithDockerfile(".");
    });

builder.AddViteApp("frontend", "./frontend")
    .WithNpmPackageInstallation()
    .WithReference(apiService)
    .WaitFor(apiService);

builder.Build().Run();

Metadata

Metadata

Assignees

Labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions