How to Have GitLab CI/CD for a .NET Aspire Project

Getting a complete CI/CD pipeline for your .NET Aspire solution doesn't have to be complicated. I've created a template that gives you everything you need to get started in minutes.

(blog post en français ici)

Watch the Video


Part 1: The Ready-to-Use Template

I've built a .NET Aspire template that comes with everything configured and ready to go. Here's what you get:

What's Included

  • A classic .NET Aspire Starter project (API and frontend)
  • Unit tests using xUnit (easily adaptable to other testing frameworks)
  • Complete .gitlab-ci.yml pipeline configuration
  • Security scanning and secret detection
  • All documentation you need

What the Pipeline Does

The pipeline runs two main jobs automatically:

  1. Build: Compiles your code
  2. Test: Runs all unit tests, scans for vulnerabilities, and checks for accidentally committed secrets (API keys, passwords, etc.)

You can see all test results directly in GitLab's interface, making it easy to track your project's health.

How to Get Started

It's simple:

  1. Clone the template repository: cloud5mins/aspire-template
  2. Replace the sample project with your own .NET Aspire code
  3. Push to your GitLab repository
  4. Watch your CI/CD pipeline run automatically

That's it! You immediately get automated builds, testing, and security scanning.

Pro Tip: The best time to set up CI/CD is when you're just starting your project because everything is still simple.


Part 2: Building the Template with GitLab Duo

Now let me share my experience creating this template using GitLab's AI assistant, GitLab Duo.

Starting Simple, Growing Smart

I didn't build this complex pipeline all at once. I started with something very basic and used GitLab Duo to gradually add features. The AI helped me:

  • Add secret detection when I asked: "How can I scan for accidentally committed secrets?"
  • Fix test execution issues when my unit tests weren't running properly
  • Optimize the pipeline structure for better performance
screen capture in VSCode using GitLab Duo to change the default location for the job SAST

Working with GitLab in VS Code

While you can edit .gitlab-ci.yml files directly in GitLab's web interface, I prefer VS Code. Here's my setup:

  1. Install the official GitLab extension from the VS Code marketplace

Once you've signed in, this extension gives you:

  • Direct access to GitLab issues and work items
  • AI-powered chat with GitLab Duo

GitLab Duo in Action

GitLab Duo became my pair programming partner. Here's how I used it:

Understanding Code: I could type /explain and ask Duo to explain what any part of my pipeline configuration does by highlighting that section.

screen capture in VSCode using GitLab Duo to explain part of the code

Solving Problems: When my solution didn't compile, I described the issue to Duo and got specific suggestions. For example, it helped me realize some projects weren't in .NET 9 because dotnet build required the Aspire workload. I could either keep my project in .NET 8 and add a before_script instruction to install the workload or upgrade to .NET 9; I picked the latest.

Adding Features: I started with just build and test, then incrementally asked Duo to help me add security scanning, secret detection, and better error handling.

Adding Context: Using /include to add the project file or the .gitlab-ci.yml file while asking questions helped Duo understand the context better.

Learn More with the Docs: During my journey, I knew Duo wasn't just making things up as it was referencing the documentation. I could continue my learning there and read more examples of how before_script is used in different contexts.

The AI-Assisted Development Experience

What impressed me most was how GitLab Duo helped me learn while building. Instead of just copying configurations from documentation, each conversation taught me something new about GitLab CI/CD best practices.

Conclusion

I think this template can be useful for anyone starting a .NET Aspire project. Ready to try it? Clone the template at cloud5mins/aspire-template and start building with confidence.

Whether you're new to .NET Aspire or CI/CD, this template gives you a good foundation. And if you want to customize it further, GitLab Duo is there to help you understand and modify the configuration.

If you think we should add more features or improve the template, feel free to open an issue in the repository. Your feedback is always welcome!

[Screen capture of the Aspire template project on GitLab




Thanks to ‪David Fowler‬ for his feedback!

Reading Notes #656

This week, we're exploring a wide range of topics, from .NET 10 previews and A/B testing to the latest in Azure development and AI. Plus, a selection of insightful podcast episodes to keep you informed and inspired.

Cloud


Programming

Open Source

  • Patrik Svensson (Patrik Svensson) - An interesting way to structure the flow that provides more detailed issues and PR with a clear purpose.

AI


Podcasts


~frank

How to convert code with GitHub Copilot, can AI really help?

Recently, someone asked me an interesting question: "Can GitHub Copilot or AI help me convert an application from one language to another?" My answer was a definitive yes! AI can not only help you write code in a new language, but it can also improve team collaboration and bridge the knowledge gap between developers who know different programming languages.

(Version française ici)

Setting Up the Environment

To demonstrate this capability, I decided to convert a COBOL application to Java—a perfect test case since I don't know either language well, which means I really needed Copilot to do the heavy lifting. All the code is available on GitHub.

The first step was setting up a proper development environment. I used a dev container and asked Copilot to help me build it. I also asked for recommendations on the best VS Code extensions for Java development. Within just a few minutes, I had a fully configured environment ready for Java development.

Choosing the Right Copilot Agent

When working with GitHub Copilot for code conversion, you have different mode to choose from:

  • Ask: Great for general questions (like asking about Java extensions)
  • Edit: Perfect for simple document editing (like modifying the generated code)
  • Agent: The powerhouse for complex tasks involving multiple files, imports, and structural changes

For code conversion projects, the Agent is your best friend. It can look at different source files, understand project structure, edit code, and even create new files on your behalf.

The Conversion Process

I used Claude 3.5 Sonnet for this conversion. Here's the simple prompt I used:

"Convert this hello business COBOL application into Java"

Copilot didn't just convert the code, it also provided detailed information about how to execute the Java application, which was invaluable since I had no Java experience.

The results varied depending on the AI model used (Claude, GPT, Gemini, etc.), but the core functionality remained consistent across different attempts. Since the original application was simple, I converted it multiple times using different prompts and models to test the consistency. Sometimes it generated a single file, other times it created multiple files: a main application and an Employee class (which wasn't in my original COBOL version). Sometimes it updated the Makefile to allow compilation and execution using make, while other times it provided instructions to use javac and java commands directly.

This variability is expected with generative AI results will differ between runs, but the core functionality remains reliable.

Real-World Challenges

Of course, the conversion wasn't perfect on the first try. For example, I encountered runtime errors when executing the application. The issue was with the data format—the original file used a flat file format with fixed length records (19 characters per record) and no line breaks.

I went back to Copilot, highlighted the error message from the terminal, and provided additional context about the 19 character record format. This iterative approach is key to successful AI assisted conversion.

"It's not working as expected, check the error in #terminalSelection. The records have fixed length of 19 characters without line breaks. Adjust the code to handle this format"

The Results

After the iterative improvements, my Java application successfully:

  • Compiled without errors
  • Processed all employee records
  • Generated a report with employee data
  • Calculated total salary (a nice addition that wasn't in the original)

While the output format wasn't identical to the original COBOL version (missing leading zeros, different line spacing), the core functionality was preserved.

Video Demonstration

Watch the complete conversion process in action:

Best Practices for AI-Assisted Code Conversion

Based on this experience, here are my recommendations:

1. Start with Small Pieces

Don't try to convert thousands of lines at once. Break your conversion into manageable modules or functions.

2. Set Up Project Standards

Consider creating a .github folder at your project root with an instructions.md file containing:

  • Best practices for your target language
  • Patterns and tools to use
  • Specific versions and frameworks
  • Enterprise standards to follow

3. Stay Involved in the Process

You're not just a spectator - you're an active participant. Review the changes, test the output, and provide feedback when things don't work as expected.

4. Iterate and Improve

Don't expect perfection on the first try. In my case, the converted application worked but produced slightly different output formatting. This is normal and expected, after all you are converting between two different languages with different conventions and styles.

Can AI Really Help with Code Conversion?

Absolutely, yes! GitHub Copilot can significantly:

  • Speed up the conversion process
  • Help with syntax and language specific patterns
  • Provide guidance on running and compiling the target language
  • Bridge knowledge gaps between team members
  • Generate supporting files and documentation

However, remember that it's generative AI, results will vary between runs, and you shouldn't expect identical output every time.

Final Thoughts

GitHub Copilot is definitely a tool you need in your toolkit for conversion projects. It won't replace the need for human oversight and testing, but it will dramatically accelerate the process and help teams collaborate more effectively across different programming languages.

The key is to approach it as a collaborative process where AI does the heavy lifting while you provide guidance, context, and quality assurance. Start small, iterate often, and don't be afraid to ask for clarification or corrections when the output isn't quite right.

Have you tried using AI for code conversion? I'd love to hear about your experiences in the comments below! Visit c5m.ca/copilot to get started with GitHub Copilot.

References


OSZAR »