Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Copilot SDK File-Based Apps 🚀

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 .cs file. No .csproj needed.

License: MIT .NET 10 Copilot SDK Validate Samples

What Is This?

This repository demonstrates two cutting-edge .NET features working together:

  1. .NET 10 File-Based Apps — Run C# files directly with dotnet run app.cs. No project file, no scaffolding, just code.
  2. 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.

Prerequisites

Quick Start

# 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.cs

That's it. No dotnet new, no .csproj, no dotnet restore. Just run.

Samples

Core Examples

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

Automation & Testing

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

Run any sample

# 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 json

Automation Use Cases

The 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

How It Works

File-Based Apps (.NET 10)

.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

GitHub Copilot SDK

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" });

Converting to a Full Project

When a file-based app outgrows its single file, convert it:

dotnet project convert samples/hello-copilot.cs

This generates a directory with a proper .csproj, preserving all your #: directives as MSBuild properties and package references.

BYOK (Bring Your Own Key)

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.

Project Structure

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

Why File-Based Apps + Copilot SDK?

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.

Contributing

Contributions welcome! Feel free to:

  • Add new sample files demonstrating Copilot SDK features
  • Improve existing samples
  • Fix bugs or improve documentation

License

MIT

Resources

About

Zero-project AI apps in C# — Combine .NET 10's file-based apps with GitHub Copilot SDK. No .csproj needed.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors