Can Source Generator created files be physically reached?
Asked Answered
F

1

16

Is there any standard method/option, how to arrange the files generated via Source Generators and added to the build process are also physically visible in the project structure (so developer can review the result code e.g. via VS solution explorer window)?

I mean other than I save the code directly to a file in the generator's Execute(), which I would expect might bring other complications (not tried yet).

EDIT:

  • According to this: https://github.com/dotnet/roslyn/issues/49249#issuecomment-809807528, no I/O is allowed within generator execution.
  • According to debug session (entering the generated code function), the generated source is at least available in the temp folder, like C:\Users\user\AppData\Local\Temp\.vsdbgsrc\some-guid\FileNameHint.cs. Unfortunately standard VS navigation (F12) does not work (regardless of debug session activity).
Fulgurous answered 9/7, 2021 at 14:45 Comment(0)
F
35

Add following to the project using the generator:

<PropertyGroup>
    <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    <CompilerGeneratedFilesOutputPath>DesiredPathForGeneratedStuff</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
Fulgurous answered 9/7, 2021 at 16:39 Comment(2)
Thanks a lot, was searching for a way to bring back the *.razor.g.cs files in .NET 6Tokyo
Note: It seems that if you specify only the first tag, then CompilerGeneratedFilesOutputPath defaults to something like $(IntermediateOutputPath)/generated, for example obj/Debug/generated.Archfiend

© 2022 - 2024 — McMap. All rights reserved.