Skip to content

dotnet run file.cs #: directive for project references #48746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
ravindUwU opened this issue Apr 28, 2025 · 0 comments
Open

dotnet run file.cs #: directive for project references #48746

ravindUwU opened this issue Apr 28, 2025 · 0 comments
Labels
Area-run-file Items related to the "dotnet run <file>" effort untriaged Request triage from a team member

Comments

@ravindUwU
Copy link

ravindUwU commented Apr 28, 2025

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<>();

// ...
@dotnet-policy-service dotnet-policy-service bot added the untriaged Request triage from a team member label Apr 28, 2025
@ravindUwU ravindUwU changed the title dotnet run file.cs #: directive to for project references dotnet run file.cs #: directive for project references Apr 28, 2025
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-run-file Items related to the "dotnet run <file>" effort untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

2 participants