來源連結Source Link

來源連結技術可讓開發人員對來自 NuGet 的 .NET 組件進行原始程式碼偵錯。Source Link is a technology that enables source code debugging of .NET assemblies from NuGet by developers. 來源連結會在建立 NuGet 套件時執行,並將原始程式碼控制中繼資料內嵌在組件和套件。Source Link executes when creating the NuGet package and embeds source control metadata inside assemblies and the package. 下載套件並在 Visual Studio 中啟用來源連結的開發人員可以逐步執行原始程式碼。Developers who download the package and have Source Link enabled in Visual Studio can step into its source code. 來源連結提供原始程式碼控制中繼資料來建立絕佳的偵錯體驗。Source Link provides source control metadata to create a great debugging experience.

使用來源連結的指示位於 dotnet/sourceLink GitHub 存放庫。Instructions for using Source Link can be found on the dotnet/sourcelink GitHub repository.

您可以使用 NuGet 套件總管確認來源連結中繼資料已成功內嵌在套件中。You can use NuGet Package Explorer to confirm that the Source Link metadata has been successfully embedded in the package. 檢查 Repository 具有認可識別碼的中繼資料是否存在,而且 .pdb 檔案會與每個目標的 .dll 一起找出。Check the Repository metadata is present with a commit identifier and that .pdb files are located with each target's .dll.

NuGet 封裝瀏覽器中的來源連結Source Link in NuGet Package Explorer

✔️ 請考慮使用來源連結以將原始程式碼控制中繼資料新增到您的組件與 NuGet 套件。✔️ CONSIDER using Source Link to add source control metadata to your assemblies and NuGet packages.

提示

您可以將偵錯工具屬性新增至您的類型,進一步加強開發人員的偵錯體驗。You can further enhance a developer's debugging experience by adding debugger attributes to your types.

✔️ CONSIDER發行符號檔 (*.pdb)。✔️ CONSIDER publishing symbol files (*.pdb).

如需最佳偵錯體驗,您的程式庫應該發佈符號檔,以及使用來源連結。For the best debugging experience your library should publish symbol files as well as use Source Link. 如需有關符號檔和符號套件的詳細資訊,請參閱符號套件For more information about symbol files and symbol packages, see Symbol packages.

✔️考慮啟用具決定性的組建。✔️ CONSIDER enabling deterministic builds.

具決定性的組建可讓您驗證產生的二進位檔是從指定的來源建立,並提供追蹤性。Deterministic builds enable verification that the resulting binary was built from the specified source and provide traceability. 如需決定性組建的詳細資訊,以及啟用它們的指示,請參閱決定性的組建For more information about deterministic builds and instructions for enabling them, see Deterministic Builds.