Add support to `dotnet package` for file-based apps
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.
dotnet pack would make sense too for .NET tools, as all necessary MSBuild parameters can be set.
dotnetpack would make sense too for .NET tools, as all necessary MSBuild parameters can be set.
@devlead tracked in #49369
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:
- Below the last
#:packagein the first group of#:packagein the file - If existing
#:package. My intuition is that it should go- Below last
using - If no
usingthen beforenamespace - If neither is present then at the top of the file after any comment that might be there
- Below last
Could also see us trying to group them with #:project references.
@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.
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/>.
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.
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?
@jjonescz what does invocation look like for add/remove for a file-based app? Is it just dotnet package add Humanizer --file myapp.cs?
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.
Came to file this issue myself :) +1
Package listing still isn’t working with file apps, and I hope it gets added at the earliest.