یک نکتهی تکمیلی: روش دیباگ پروژههای Source Generator در Visual Studio
برای اینکار اولین تغییر مورد نیاز، افزودن تنظیم زیر به فایل csproj پروژهی Source Generator است:
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<IsRoslynComponent>true</IsRoslynComponent>
سپس در Solution explorer به خواص پروژهی source generator مراجعه کرده و در برگهی Debug آن، دراپداون Launch را انتخاب و گزینهی IsRoslynComponent تنظیمی را انتخاب کنید.
در ادامه در هر قسمتی از کدهای Source generator که نیاز به دیباگ هست، برای مثال ابتدای متد Execute، باید چندسطر زیر را اضافه کرد:
#if DEBUG
if (!Debugger.IsAttached)
{
Debugger.Launch();
}
#endif
این کدها فقط در حالت دیباگ اضافه شده و با کامپایل برنامه و یا فشردن دکمهی F5، سبب نمایش پنجرهی جدید choose just-in-time debugger میشوند. در اینجا میتوانید یک وهلهی جدید از ویژوال استودیو را برای دیباگ انتخاب کنید و یا میتوان همان وهلهی جاری را نیز انتخاب کرد تا سبب اجرای مجدد ویژوال استودیو نشود. در این حالت debugger به پروژه متصل شده و امکان دیباگ آن میسر میشود. ابتدا ویژوال استودیو بر روی سطر Debugger.Launch، متوقف میشود. سپس break-pointهای مدنظر خود را قرار داده و با فشردن دکمهی F5 میتوان به آنها رسید و آنها را دیباگ کرد.