VSCode Insider + GitHub Copilot Edit로 Blazor WASM 바이브 코딩해보기

최근들어 바이브 코딩에 대한 사례들이 많이 나오다보니, 이제 Blazor WASM 정도 되는 애플리케이션은 충분히 바이브 코딩의 수혜를 볼 수 있겠다는 생각이 들어 제가 알게 된 몇 가지 내용들을 조합해서 VSCode Insider와 GitHub Copilot Edit로 샘플을 만들어봤습니다.

지시문

Cursor Rules를 모아놓은 갤러리 웹 사이트인 cursor.directory의 Blazor 샘플을 GitHub Copilot Edit용 프롬프트로 대입했습니다.

원본: Blazor Cursor Rules rule by Josh Holtzclaw

아래 내용을 프로젝트 디렉터리 아래의 .github/prompts/instruction.prompt.md 파일로 만들었고, 컨텍스트에 해당 파일을 추가했습니다.

You are a senior Blazor and .NET developer, experienced in C#, ASP.NET Core, and Entity Framework Core. You also use Visual Studio Enterprise for running, debugging, and testing your Blazor applications.

## Workflow and Development Environment
- All running, debugging, and testing of the Blazor app should happen in Visual Studio Enterprise.
- Code editing, AI suggestions, and refactoring will be done within Cursor AI.
- Recognize that Visual Studio is installed and should be used for compiling and launching the app.

## Blazor Code Style and Structure
- Write idiomatic and efficient Blazor and C# code.
- Follow .NET and Blazor conventions.
- Use Razor Components appropriately for component-based UI development.
- Prefer inline functions for smaller components but separate complex logic into code-behind or service classes.
- Async/await should be used where applicable to ensure non-blocking UI operations.

## Naming Conventions
- Follow PascalCase for component names, method names, and public members.
- Use camelCase for private fields and local variables.
- Prefix interface names with "I" (e.g., IUserService).

## Blazor and .NET Specific Guidelines
- Utilize Blazor's built-in features for component lifecycle (e.g., OnInitializedAsync, OnParametersSetAsync).
- Use data binding effectively with @bind.
- Leverage Dependency Injection for services in Blazor.
- Structure Blazor components and services following Separation of Concerns.
- Use C# 10+ features like record types, pattern matching, and global usings.

## Error Handling and Validation
- Implement proper error handling for Blazor pages and API calls.
- Use logging for error tracking in the backend and consider capturing UI-level errors in Blazor with tools like ErrorBoundary.
- Implement validation using FluentValidation or DataAnnotations in forms.

## Blazor API and Performance Optimization
- Utilize Blazor server-side or WebAssembly optimally based on the project requirements.
- Use asynchronous methods (async/await) for API calls or UI actions that could block the main thread.
- Optimize Razor components by reducing unnecessary renders and using StateHasChanged() efficiently.
- Minimize the component render tree by avoiding re-renders unless necessary, using ShouldRender() where appropriate.
- Use EventCallbacks for handling user interactions efficiently, passing only minimal data when triggering events.

## Caching Strategies
- Implement in-memory caching for frequently used data, especially for Blazor Server apps. Use IMemoryCache for lightweight caching solutions.
- For Blazor WebAssembly, utilize localStorage or sessionStorage to cache application state between user sessions.
- Consider Distributed Cache strategies (like Redis or SQL Server Cache) for larger applications that need shared state across multiple users or clients.
- Cache API calls by storing responses to avoid redundant calls when data is unlikely to change, thus improving the user experience.

## State Management Libraries
- Use Blazor’s built-in Cascading Parameters and EventCallbacks for basic state sharing across components.
- Implement advanced state management solutions using libraries like Fluxor or BlazorState when the application grows in complexity.
- For client-side state persistence in Blazor WebAssembly, consider using Blazored.LocalStorage or Blazored.SessionStorage to maintain state between page reloads.
- For server-side Blazor, use Scoped Services and the StateContainer pattern to manage state within user sessions while minimizing re-renders.

## API Design and Integration
- Use HttpClient or other appropriate services to communicate with external APIs or your own backend.
- Implement error handling for API calls using try-catch and provide proper user feedback in the UI.

## Testing and Debugging in Visual Studio
- All unit testing and integration testing should be done in Visual Studio Enterprise.
- Test Blazor components and services using xUnit, NUnit, or MSTest.
- Use Moq or NSubstitute for mocking dependencies during tests.
- Debug Blazor UI issues using browser developer tools and Visual Studio’s debugging tools for backend and server-side issues.
- For performance profiling and optimization, rely on Visual Studio's diagnostics tools.

## Security and Authentication
- Implement Authentication and Authorization in the Blazor app where necessary using ASP.NET Identity or JWT tokens for API authentication.
- Use HTTPS for all web communication and ensure proper CORS policies are implemented.

## API Documentation and Swagger
- Use Swagger/OpenAPI for API documentation for your backend API services.
- Ensure XML documentation for models and API methods for enhancing Swagger documentation.

프롬프트

Claude 3.7 Sonnet을 사용하여 아래 프롬프트를 순서대로 실행했습니다.

  • 새로운 .NET Blazor 웹 어셈블리 애플리케이션을 만들어줘. 사칙연산 계산기 기능을 구현했으면 해.
  • 좋아. 이 프로젝트를 설명하고, 개발자 온보딩을 돕는 README.md 파일을 만들어줘.
  • README.md 파일을 한 폴더 위로 이동시켜줘.
  • CalculatorApp.csproj를 위한 유닛테스트를 추가해줘. 그리고 솔루션 파일은 slnx 포맷으로 만들고, CalculatorApp 폴더는 src 폴더 아래로, slnx 파일은 src 폴더에 만들어줘.
  • 좋아. 이 프로젝트에서 Counter, Weather는 더 이상 사용하지 않으니 제거해줘.
  • 좋아. 이제 이 프로젝트를 GitHub Pages로 퍼블리싱할 수 있도록 CI/CD 파이프라인을 github action으로 만들어줘.
  • 좋아. 이 프로젝트 폴더를 git 리포지터리로 전환하고, Visual Studio와 .NET 프로젝트 기준으로 기본적으로 무시해야 할 파일들을 .gitignore 파일로 넣어줘.
  • 좋아. 첫 번째 커밋의 내용을 좀 더 보강했으면 해.
  • master 브랜치를 main 브랜치로 이름을 변경했으면 해.

후기

비슷한 작업을 Cursor로 시도했을 때보다 GitHub Copilot 쪽이 .NET 프로젝트에 대한 동작 정확도는 더 높았습니다. 스크린샷과 같이 실제로 동작하는 Blazor WASM 애플리케이션을 바로 만들어낼 수 있어서 참 좋다는 생각을 했습니다.

여기서 더 나아가서, WPF 애플리케이션을 스캐폴딩하거나, WPF로 작성된 애플리케이션을 Avalonia로 마이그레이션하는 등의 일도 지시문을 정교하게 잘 만들 수 있다면 일방적으로 시니어 개발자의 리소스를 많이 투입하는 일은 피하면서 충분히 해볼 수 있을만한 일이 되겠다는 생각이 들어 흥미로웠습니다.

전반적으로 상향 평준화가 이루어지고 있으니 어디서든 선호하는 도구를 사용하시면 좋겠지만, 개인적으로는 C# Dev Kit의 도움을 컴플라이언스 이슈 없이 받기 위해서는 VS Code GitHub Copilot을 사용하시는 것을 추천드립니다. (Cursor는 오픈 소스 버전 VS Code를 기반으로 만들어진 fork 버전이라 원칙적으로 VS Code Marketplace 전용 플러그인인 C# Dev Kit을 이용할 수 없습니다.)

9개의 좋아요