使用自定义说明功能自动向提示添加自定义的上下文详细信息。 Copilot Chat 使用这些说明根据个人偏好定制响应。
使用 .github/copilot-instructions.md 文件
若要使用 .github/copilot-instructions.md 文件,请执行以下步骤:
创建或添加存储库根目录中命名
.github/copilot-instructions.md的自定义说明文件。若要启用该功能,请选择“启用从 .github/copilot-instructions.md 文件加载的自定义说明”,并将其添加到工具>选项>GitHub>Copilot Copilot>Chat 中的请求。
自定义说明在聊天视图或内联聊天中不可见。 但是,当 Copilot 使用 .github/copilot-instructions.md 该文件时,它会在响应的“引用”列表中列出该文件。
启用用户级指令
除了存储库的自定义说明之外,还可以定义适用于所有 Copilot 会话的用户级首选项。 用户级首选项保存到 %USERPROFILE%/copilot-instructions.md。
将用户级首选项用于个人编码标准、首选模式或希望 Copilot 遵循的工作流约定,即使不使用存储库也是如此。 存储库级别的指令在 .github/copilot-instructions.md 中仍会与用户级别的偏好一起应用,因此 Copilot 会遵循任何共享的标准。
copilot-instructions.md如果文件夹中不存在%USERPROFILE%该文件,则可以在该位置创建该文件。
自定义说明文件格式
自定义指令文件是 markdown 文件(.md 文件扩展名),包含你定义的每个节的主标题和子标题。
示例
# Copilot Instructions
## Persona
- I am a veteran SQL Server data professional with 20+ years of experience.
- Use a helpful, collegial tone. Keep explanations brief, but provide enough context to understand the code.
- Every so often, share a SQL or database-related fun fact or historical tidbit.
## Safety and execution guardrails
- Treat my database as a production database unless I explicitly state it's a dev or test environment.
- For any query that could scan large tables, include a cautious version first (TOP, date filter, or indexed predicate), but offer to give me the full version if I want it
## Code style
- Use tabs instead of spaces for indentation
- Always schema-qualify object names (e.g., dbo.Customer)
- Place JOIN conditions on separate lines
- Include header comments with author, date, parameters, change history and description for all stored procedures and functions
- Always qualify column names with table aliases
- Use short, readable aliases based on table name
## Naming conventions:
- Tables: PascalCase singular (Customer, Order, Product)
- Primary keys: <TableName>ID (CustomerID)
- Foreign keys: <ReferencedTable>ID
- Stored procedures: usp_<Action><Entity>
- Views: v_<Description>
- Functions: fn_<Description>