Referencing a file in GitHub Copilot for Visual Studio

This post has been republished via RSS; it originally appeared at: Microsoft Developer Community Blog articles.

When you start a new project from scratch in Visual Studio, a few files get created. Many templates are available, for many types of applications, from simple console apps to complex web applications, as well as mobile, serverless, and many many more. All these projects consist of multiple files. You have your code files, containing the software that will be run, organized in classes, with often each class in its own file. You have the configuration files, be it JSON, XML, YAML or other. You may even have data files, embedded in the application when it's built. 


In the new video we just posted, my colleague Gwyn shows how you can use the Hash shortcut (#) to reference another file.


Context is everything

As we mentioned many times in this series, what makes a good Copilot output starts with a good prompt. But the prompt is more than "just" asking the large language model to do something. You also need to provide context. In AI parlance, we talk about "grounding" the model with data, or Retrieval Augmented Generation RAG.


Through its training, Copilot has access to general knowledge about the platform that you are using. It also has specific knowledge about libraries and frameworks. But what's missing is your own private code, the code that the rest of the world doesn't see. For example, you can let Copilot know that another file contains a series of methods that the current class can use.


In the example, Gwyn points Copilot to a JSON file containing data so a test can be generated. This adds precious context so that Copilot generates the correct code faster. 


More information

As always you can find many resources in this collection. I also added all the blog posts and videos in this series so you can easily find past episodes and gain more knowledge. And of course, the best way to stay up to date is to subscribe to the Visual Studio YouTube channel, the Visual Studio DevBlog and of course this blog here.

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.