dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
509 stars 258 forks source link

Support source generator debugging in the new Launch Profiles UI #850

Closed drewnoakes closed 2 years ago

drewnoakes commented 3 years ago

In Dev17 we have a new UI for launch profiles, which replaces the legacy ILaunchSettingsUIProvider interface. Rather than having each provider specify it's own UI components, we now expect data about properties in order to present a unified experience.

The source generator debugger support in this repo should be extended to provide the relevant data for that experience, for launch profiles with command name DebugRoslynComponent.

Without support, editing of source generator debugging profiles is not available for C# projects in Dev17.

Docs exist to walk through this process here: https://github.com/dotnet/project-system/tree/main/docs/repo/property-pages

In particular the doc on adding a new launch profile kind, and on property specification.

Ping @drewnoakes or @tmeschter for help if anything is unclear.

tmeschter commented 3 years ago

Yeah, feel free to ping us for reviews or questions. Any issues you encounter are likely to affect others as well so we want to know about them.

jmarolf commented 3 years ago

Since this is going to be the only way to view Launch Profiles in VS 2022 we will need to make a change here to fix this this month.

drewnoakes commented 2 years ago

@jmarolf @chsienki a ping on this, as it will be a regression in 17.0 if omitted.

drewnoakes commented 2 years ago

Also reported in https://developercommunity.visualstudio.com/t/Debugging-Source-Generators-via-Debug-La/1511451.

jmarolf commented 2 years ago

fixed with https://github.com/dotnet/roslyn-sdk/pull/896

ignatandrei commented 2 years ago

Do we have a tutorial about this somewhere ?

zhen8838 commented 2 years ago

@ignatandrei I record a video:

https://user-images.githubusercontent.com/26156999/153815974-65ce83d0-a3a2-4c07-8777-9d691d0243bd.mp4

susch19 commented 2 years ago

If this option doesn't show up for you in VS2022, make sure you have the .NET Compiler Platform SDK Component installed. I somehow missed that and wondered why it didn't show up.

TorreyGarland commented 2 years ago

Can these new instructions be added to the "official" documentation for Source/Incremental Generators?

I tried following the video and it is still not working for me.

susch19 commented 2 years ago

Can these new instructions be added to the "official" documentation for Source/Incremental Generators?

I tried following the video and it is still not working for me.

Does the dropdown menu doesn't show the option? Did you add <IsRoslynComponent>true</IsRoslynComponent> to the source code generator csproj PropertyGroup (Shown in the first few seconds of the video)? Did you open the menu on the source code generator csproj?

If you can't select the target project, then check whether you have the source code generator referenced in the target project like so <ProjectReference Include="..\YourSourceCodeGeneratorName\YourSourceCodeGeneratorName.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

That's all that should be needed, including the .NET Compiler Platform SDK, but I imagine you have this installed

If all that doesn't help, you can still create the launchSettings.json by yourself:

{
  "profiles": {
    "Your.SourceCode.Generator.Name": {
      "commandName": "DebugRoslynComponent",
      "targetProject": "..\\TargetProject\\TargetProject.csproj"
    }
  }
}
TorreyGarland commented 2 years ago

Can these new instructions be added to the "official" documentation for Source/Incremental Generators? I tried following the video and it is still not working for me.

Does the dropdown menu doesn't show the option? Did you add <IsRoslynComponent>true</IsRoslynComponent> to the source code generator csproj PropertyGroup (Shown in the first few seconds of the video)? Did you open the menu on the source code generator csproj?

If you can't select the target project, then check whether you have the source code generator referenced in the target project like so <ProjectReference Include="..\YourSourceCodeGeneratorName\YourSourceCodeGeneratorName.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

That's all that should be needed, including the .NET Compiler Platform SDK, but I imagine you have this installed

If all that doesn't help, you can still create the launchSettings.json by yourself:

{
  "profiles": {
    "Your.SourceCode.Generator.Name": {
      "commandName": "DebugRoslynComponent",
      "targetProject": "..\\TargetProject\\TargetProject.csproj"
    }
  }
}

project-file

launch-profiles

launch-settings-2

solution-explorer

error-message

ClassLibrary3 is a .netstandard 2.0 class library that holds an IIncrementalGenerator instance. BlazorApp1 is the sandbox project that will consume that code generated by ClassLibrary3.

Source generation works. Debugging as described here does not, and debugger.launch() is a pain.

susch19 commented 2 years ago

@TorreyGarland This problem is known and tracked here: https://github.com/dotnet/roslyn/issues/55802

So one or multiple of your dependencies is the problem, so either remove one after another, until it works, create a new generator and add them until it doesn't work or wait for a fix.

TorreyGarland commented 2 years ago

strange... works now perfectly with all previous dependencies on both SourceGenerators and IncrementalGenerators.

I didn't update the sdk.

Maybe good old fashioned restart computer worked.

Thanks for quickly looking into this.

TorreyGarland commented 2 years ago

I spoke too soon... it works perfectly for a console app.

it failed with the "filename or extension is too long" message for a Blazor Server App project.

drewnoakes commented 2 years ago

That's the same error message discussed in https://github.com/dotnet/roslyn/issues/55802.

TorreyGarland commented 2 years ago

That's the same error message discussed in dotnet/roslyn#55802.

I'm sorry, I didn't see anything specific to blazor apps in that discussion.

JoanComasFdz commented 2 years ago

This has worked for me. I have tried to streamline the instructions here:

https://github.com/JoanComasFdz/dotnet-how-to-debug-source-generator-vs2022

TorreyGarland commented 2 years ago

This has worked for me. I have tried to streamline the instructions here:

https://github.com/JoanComasFdz/dotnet-how-to-debug-source-generator-vs2022

try it with blank blazor server app. does it work for you?

JoanComasFdz commented 2 years ago

This has worked for me. I have tried to streamline the instructions here: https://github.com/JoanComasFdz/dotnet-how-to-debug-source-generator-vs2022

try it with blank blazor server app. does it work for you?

I just followed my own instructions and yes it works: https://github.com/JoanComasFdz/BlazorApp1

Make sure tu put the breakpoints in the SourceGenerator Initialize and Execute methods to see it working.

Also for reference: I am using VS 2022 17.1.0

TorreyGarland commented 2 years ago

This has worked for me. I have tried to streamline the instructions here: https://github.com/JoanComasFdz/dotnet-how-to-debug-source-generator-vs2022

try it with blank blazor server app. does it work for you?

I just followed my own instructions and yes it works: https://github.com/JoanComasFdz/BlazorApp1

Make sure tu put the breakpoints in the SourceGenerator Initialize and Execute methods to see it working.

Also for reference: I am using VS 2022 17.1.0

thank you for looking into to this

ignatandrei commented 2 years ago

Still does not work for me. I am using VS2022 vs 17.1.1 The "Roslyn" menu does not appear , even if I have downloaded https://github.com/JoanComasFdz/BlazorApp1

Any idea why?

ignatandrei commented 2 years ago

.NET Compiler Platform SDK

Solved with https://github.com/dotnet/roslyn-sdk/issues/850#issuecomment-1041839050 . THanks. !

TorreyGarland commented 2 years ago

.NET Compiler Platform SDK

Solved with #850 (comment) . THanks. !

this worked with a Blazor Server app? I have the most recent SDK and it still failed.

HClausing commented 2 years ago

I've tried this way for debugging, but got this on terminal, related to target project:

image

But the target project compiles well on Visual Studio, and I can debug it without throubles.

The files listed on Errors CS2001 really don't exist. I really don't know why it's happening.

Generator launchSettings.json:

{
  "profiles": {
    "Debug Generators": {
      "commandName": "DebugRoslynComponent",
      "targetProject": "..\\..\\Desktop\\EficazFramework.WPF\\EficazFramework.WPF.csproj"
    }
  }
}

Target project's csproj file:

  <ItemGroup>
    <ProjectReference Include="..\..\CodeGenerators\EficazFramework.Generators\EficazFramework.Generators.csproj" 
                      ReferenceOutputAssembly="false" 
                      OutputItemType="Analyzer" />
  </ItemGroup>
HClausing commented 2 years ago

I've figured that it maybe related to spaces on project folder's name. After renaming "DataGrid Columns" to "DataGridColumns" the number of errors reduced:

image

UPDATE

After moving to another folder, without any spaces on full path, everything goes fine.