Skip to content

Output from publishing file-based app using web SDK is included by default items, causes errors on subsequent publish #51391

@DamianEdwards

Description

@DamianEdwards

The default output directory for publishing file-based apps, ./artifacts/<app name>, next to the app file, is not excluded from the app's default non-compile items. This is especially problematic for app's using the Microsoft.NET.Sdk.Web SDK which includes *.json files in its default items. This results in issues if you call publish multiple times without clearing the output directory, as the JSON files in the output directory get included in the next publish command.

Repro steps:

  1. Create a file-based app, e.g. app.cs using the web SDK:
    #:sdk Microsoft.NET.Sdk.Web
    #:property PublishAot=false
    var builder = WebApplication.CreateBuilder(args);
    var app = builder.Build();
    app.MapGet("/", () => "Hello World!");
    app.Run();
  2. Run dotnet publish app.cs
  3. There will now be an artifacts/app directory next to the app.cs file, containing the publish output
  4. Run dotnet publish app.cs again
    a. This can also be a container publish:
    dotnet publish app.cs --os linux --arch x64 -t:PublishContainer
  5. Observe the warnings about files being in use. If the publish succeeds (I've seen it fail, I've seen retries on the file in use succeed), note the publish output directory now contains "recursive" items, e.g. ./artifacts/app/artifacts/app/*.json

We might want to consider updating the default non-compile items globs for file-based apps to exclude the artifacts directory.

Metadata

Metadata

Labels

Area-run-fileItems related to the "dotnet run <file>" effort

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions