sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Add support to `dotnet package` for file-based apps

Open DamianEdwards opened this issue 7 months ago • 4 comments

File-based apps are currently supported by the dotnet restore, dotnet build, and dotnet run commands. Supporting them in dotnet publish is being considered in #49189. We should consider supporting file-based apps with the dotnet package add/list/remove commands so that it's easy to explore and manage the packages they depend on, in the same way that can be done for solutions and projects.

DamianEdwards avatar May 29 '25 21:05 DamianEdwards

dotnet pack would make sense too for .NET tools, as all necessary MSBuild parameters can be set.

devlead avatar Jun 04 '25 17:06 devlead

dotnet pack would make sense too for .NET tools, as all necessary MSBuild parameters can be set.

@devlead tracked in #49369

DamianEdwards avatar Jun 17 '25 00:06 DamianEdwards

One item we're going to need to flesh out here is where do we put the #:package reference for the following cases. My initial intuition is the following:

  1. Below the last #:package in the first group of #:package in the file
  2. If existing #:package. My intuition is that it should go
    1. Below last using
    2. If no using then before namespace
    3. If neither is present then at the top of the file after any comment that might be there

Could also see us trying to group them with #:project references.

jaredpar avatar Jun 20 '25 17:06 jaredpar

@jaredpar can we look at the logic used when adding <PackageReference /> and attempt to map that? That said, I think your intuition is good here.

DamianEdwards avatar Jun 20 '25 20:06 DamianEdwards

It looks like the actual implementation of dotnet package add is inside nuget but I assume we don't want to modify that (i.e., make nuget aware of file based apps), we only want to modify dotnet CLI.

Another thing - I guess we should also support dotnet reference add to add #:project just like it can add <ProjectReference/>.

jjonescz avatar Jun 24 '25 15:06 jjonescz

I assume we want to support Central Package Management as well with this. The logic for updating Directory.Packages.props also lives in NuGet so I guess it will need to be a bit duplicated here in dotnet CLI.

jjonescz avatar Jun 26 '25 15:06 jjonescz

That's unfortunate - I wonder if more of the domain logic of the commands could be pushed into an API layer that the Commands just consume?

baronfel avatar Jun 26 '25 15:06 baronfel

@jjonescz what does invocation look like for add/remove for a file-based app? Is it just dotnet package add Humanizer --file myapp.cs?

DamianEdwards avatar Jul 31 '25 22:07 DamianEdwards

Yes. Or the legacy form dotnet add file.cs package Humanizer or dotnet add package Humanizer --file app.cs.

Other flags like --no-restore or --version also work.

jjonescz avatar Aug 01 '25 06:08 jjonescz

Came to file this issue myself :) +1

claudiaregio avatar Sep 25 '25 23:09 claudiaregio

Package listing still isn’t working with file apps, and I hope it gets added at the earliest.

egvijayanand avatar Nov 20 '25 14:11 egvijayanand