Description
Is your feature request related to a problem? Please describe.
The dotnet run file.cs
document lists #:
directives to specify the SDK, properties and NuGet package references of the implicit project file, but doesn't list a directive to reference a C# project.
Describe the solution you'd like
-
A
#:project
directive (or equivalent) to reference a "full" C# project by its absolute/relative path, which translates to<ProjectReference Include="..." />
in the implicit project file. -
Maybe a
#:reference
directive to reference .DLLs in a similar way, which translates to<Reference Include="..." />
to my understanding? (although, I don't have any experience with this 😅).
Additional context
I think project references would be very useful to ship smol helper scripts alongside a main project?
e.g., a main ASP.NET Core web project Server/Server.csproj
with Server/Program.cs
and an EF Core DB context Server/Db.cs
, and a scripts/firstRun.cs
helper script which sets up the project for local development by creating an initial user, etc. using the DB context/services of the main project.
Program.cs
would look roughly like,
namespace Server;
public class Program
{
public static WebApplication Build(string[]? args = null)
{
var builder = WebApplication.CreateBuilder(args ?? []);
builder.Services.AddDbContext<Db>();
// Services configured here...
return builder.Build();
}
public static void Main(string[] args)
{
var app = Build(args);
// Request pipeline configured here.
app.Run();
}
}
...and the firstRun.cs
helper script would look like,
#:project ../Server/Server.csproj
var server = Server.Program.Build();
using var scope = server.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<>();
// ...