Zero-project AI apps in C# — Combine .NET 10's file-based apps (
dotnet run app.cs) with the GitHub Copilot SDK to build AI-powered applications in a single.csfile. No.csprojneeded.
This repository demonstrates two cutting-edge .NET features working together:
- .NET 10 File-Based Apps — Run C# files directly with
dotnet run app.cs. No project file, no scaffolding, just code. - GitHub Copilot SDK — Programmatic access to GitHub Copilot's agent runtime. The same engine behind Copilot CLI, available as a NuGet package.
The result: single-file AI applications you can run instantly.
- .NET 10 SDK installed
- GitHub Copilot CLI installed and available in PATH
- A GitHub Copilot subscription (free tier available)
- Authenticated with Copilot CLI (
copilot auth login)
# Clone this repo
git clone https://github.com/Michspirit99/copilot-sdk-file-apps.git
cd copilot-sdk-file-apps
# Run any example — no build step required!
dotnet run samples/hello-copilot.csThat's it. No dotnet new, no .csproj, no dotnet restore. Just run.
| File | Description |
|---|---|
samples/hello-copilot.cs |
Minimal "Hello World" — send a prompt, get a response |
samples/streaming-chat.cs |
Stream responses token-by-token in real time |
samples/interactive-chat.cs |
Full interactive chat loop in the terminal |
samples/code-reviewer.cs |
AI-powered code review — pass any file for analysis |
samples/custom-tools.cs |
Define custom C# functions callable by AI |
samples/multi-model.cs |
Compare responses across different models |
samples/file-summarizer.cs |
Summarize any text file using AI |
samples/git-commit-writer.cs |
Generate commit messages from staged changes |
| File | Description |
|---|---|
samples/playwright-agent.cs |
🌐 AI-driven browser automation with Playwright |
samples/log-analyzer.cs |
📊 Analyze logs for errors, security issues, performance |
samples/api-test-generator.cs |
🧪 Generate API tests from OpenAPI/Swagger specs |
samples/test-data-generator.cs |
🎲 Generate realistic test data in JSON/SQL/CSV |
# Basic usage
dotnet run samples/hello-copilot.cs
# Core examples with arguments
dotnet run samples/code-reviewer.cs -- path/to/file.cs
dotnet run samples/file-summarizer.cs -- README.md
# Automation examples
dotnet run samples/playwright-agent.cs -- https://example.com "Describe the page"
dotnet run samples/log-analyzer.cs -- app.log errors
dotnet run samples/api-test-generator.cs -- swagger.json xunit
dotnet run samples/test-data-generator.cs -- user 50 jsonThe automation samples demonstrate practical AI-powered workflows:
🌐 Browser Automation (playwright-agent.cs)
- Navigate websites and extract data
- Fill forms and interact with pages
- Automated testing scenarios
- Web scraping with AI guidance
📊 Log Analysis (log-analyzer.cs)
- Find and categorize errors
- Security threat detection
- Performance bottleneck identification
- Automated incident reports
🧪 API Testing (api-test-generator.cs)
- Generate xUnit/NUnit test cases
- Create Postman collections
- Generate curl command references
- Test coverage analysis
🎲 Test Data (test-data-generator.cs)
- Realistic user profiles
- Product catalogs
- Order histories
- Custom schemas in JSON/SQL/CSV
.NET 10 introduced dotnet run app.cs — the ability to run a single .cs file without a project. File-level directives replace what .csproj files traditionally did:
#:package GitHub.Copilot.SDK@0.1.23 // NuGet package reference
#:package Microsoft.Extensions.AI@10.2.0 // Add as many as you need
// Your code starts here — top-level statements, no boilerplate
Console.WriteLine("Hello from a file-based app!");Key directives:
#:package PackageName@Version— Add a NuGet package reference#:sdk Microsoft.NET.Sdk.Web— Change the SDK (for web apps)#:property Key=Value— Set MSBuild properties
The Copilot SDK (GitHub.Copilot.SDK) gives you programmatic access to the Copilot agent runtime:
await using var client = new CopilotClient();
await client.StartAsync();
await using var session = await client.CreateSessionAsync(new SessionConfig
{
Model = "gpt-4o"
});
session.On(evt =>
{
if (evt is AssistantMessageEvent msg)
Console.WriteLine(msg.Data.Content);
});
await session.SendAsync(new MessageOptions { Prompt = "Explain async/await" });When a file-based app outgrows its single file, convert it:
dotnet project convert samples/hello-copilot.csThis generates a directory with a proper .csproj, preserving all your #: directives as MSBuild properties and package references.
Don't have a Copilot subscription? Use your own API keys:
var session = await client.CreateSessionAsync(new SessionConfig
{
Provider = new ProviderConfig
{
Type = "openai",
BaseUrl = "https://api.openai.com/v1",
ApiKey = Environment.GetEnvironmentVariable("OPENAI_API_KEY")!
}
});See samples/custom-tools.cs for a complete BYOK example pattern.
copilot-sdk-file-apps/
├── samples/ # All runnable examples
│ ├── hello-copilot.cs # Minimal example
│ ├── streaming-chat.cs # Streaming responses
│ ├── interactive-chat.cs # Interactive terminal chat
│ ├── code-reviewer.cs # AI code review
│ ├── custom-tools.cs # Custom tool definitions
│ ├── multi-model.cs # Multi-model comparison
│ ├── file-summarizer.cs # File summarization
│ ├── git-commit-writer.cs # Git commit message generation
│ ├── playwright-agent.cs # Browser automation
│ ├── log-analyzer.cs # Log file analysis
│ ├── api-test-generator.cs # API test generation
│ └── test-data-generator.cs # Test data generation
├── README.md
├── LICENSE
├── .gitignore
└── .github/
└── FUNDING.yml
| Traditional Approach | File-Based Approach |
|---|---|
dotnet new console |
Just create a .cs file |
Edit .csproj for packages |
#:package directive inline |
dotnet restore && dotnet run |
dotnet run app.cs |
| Multiple files for simple tasks | Single file, top-level statements |
| Project scaffolding overhead | Zero ceremony |
File-based apps make C# as approachable as Python for quick AI experiments while retaining the full power of the .NET ecosystem.
Contributions welcome! Feel free to:
- Add new sample files demonstrating Copilot SDK features
- Improve existing samples
- Fix bugs or improve documentation