Skip to main content

Generated source

Most IDEs allow you to view the source code generated by Mapperly. Usually you can jump to the implementation via the partial mapper method. If your IDE doesn't easily allow this or if you want to check in the generated source into source control, you can emit the generated files.

To emit the generated files to disk set the EmitCompilerGeneratedFiles property:

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
</PropertyGroup>

By default the files are written to {BaseIntermediateOutpath}/generated/{Assembly}/Riok.Mapperly/{GeneratedFile}. With BaseIntermediateOutpath for example being obj/Debug/net8.0.

The output path can be customized via the CompilerGeneratedFilesOutputPath property. This can be used to check the generated files into VCS. If the project path is inside the project directory structure, the files are picked up by the compiler additionally to the in-memory source generator output. Therefore the files need to be explicitly removed from the compilation.

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<!-- Exclude the output of source generators from the compilation, show it in the IDE -->
<Compile Remove="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
<None Include="$(CompilerGeneratedFilesOutputPath)/**/*.cs" />
</ItemGroup>
info

Mapperly only emits updated source code on build. You won't see the updated mapper code or mapper diagnostics until you perform a build.

This is done for performance reasons, otherwise the IDE could become laggy.