Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
drewnoakes opened this issue Jun 2, 2021 · 25 comments
Closed

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

drewnoakes opened this issue Jun 2, 2021 · 25 comments
Assignees
Labels
Area-Source Generators SDK support for source generators

Comments

@drewnoakes
Copy link
Member

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
Copy link
Contributor

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.

@chsienki chsienki self-assigned this Jun 3, 2021
@sharwell sharwell added the Area-Source Generators SDK support for source generators label Jun 23, 2021
@jmarolf
Copy link
Contributor

jmarolf commented Aug 26, 2021

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
Copy link
Member Author

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

@drewnoakes
Copy link
Member Author

@jmarolf
Copy link
Contributor

jmarolf commented Sep 23, 2021

fixed with #896

@jmarolf jmarolf closed this as completed Sep 23, 2021
@ignatandrei
Copy link

Do we have a tutorial about this somewhere ?

@zhen8838
Copy link

@ignatandrei I record a video:

source_generator.debug.mp4

@susch19
Copy link

susch19 commented Feb 16, 2022

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
Copy link

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
Copy link

susch19 commented Feb 20, 2022

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
Copy link

TorreyGarland commented Feb 20, 2022

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
Copy link

susch19 commented Feb 20, 2022

@TorreyGarland
This problem is known and tracked here:
dotnet/roslyn#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
Copy link

TorreyGarland commented Feb 26, 2022

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
Copy link

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
Copy link
Member Author

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

@TorreyGarland
Copy link

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
Copy link

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
Copy link

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
Copy link

JoanComasFdz commented Mar 1, 2022

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
Copy link

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
Copy link

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
Copy link

.NET Compiler Platform SDK

Solved with #850 (comment) . THanks. !

@TorreyGarland
Copy link

.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
Copy link

HClausing commented Apr 13, 2022

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
Copy link

HClausing commented Apr 13, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Source Generators SDK support for source generators
Projects
None yet
Development

No branches or pull requests