Source file path ends up written in PDB and it may also be read from within the DLL via CallerFileNameAttribute, after being transformed via path map.
The current implementation does not work with path map though. Relative paths won't be translated via path map correctly since the map expects absolute paths as inputs.
One side effect of applying path map to paths on Windows is a normalization of directory separators (\ to /). If path map does not match the path when built on Windows \ will remain in the path. If that path is read on Linux (e.g. via reading CallerFileNameAttribute value) Path APIs will fail to recognize the directory separator.
This will also cause unnecessary differences between builds on Windows and Linux.
Besides, it introduces additional inconsistencies throughout the system that need to be handled (e.g. in EnC).
Proposal
The relative paths of source generated files should be combined with the directory where other compiler outputs (e.g. xml doc comments, pdb, dll) are stored.
UPDATE - impact on reproducibility:
Additional problem occurs when source generator produces #line directives that refer to additional files (e.g. .razor.g.cs files refer to .razor files).
If the generator produced #line directives with full paths then these paths will be correctly mapped via /pathmap when stored in the PDB. However, the generated source will also be stored in the PDB as is - i.e. with the full, unmapped paths in the #line directives. This creates a dependency on the directory from which the project is built and making the build non-reproducible. So the generator needs to emit #line directives with relative paths. How does the generator know the path of the generated file relative to the target path?
Note: Razor source generator currently uses full paths and thus breaks reproducible builds.
UPDATE - impact on EnC/Hot Reload:
Combination of source generated files and file scoped types are causing issues with Hot Reload - e.g. #72331.
The IDE uses relative path for the source generated file, while the compiler is using absolute path.
Generated file class ends up having two different path hashes in metadata name.
Proposal
If /pathmap is specified the generator driver will apply it to all #line directives in the generated source before adding it to the resulting compilation.
Use the same approach as #71879: Use /generatedfilesout or /out path as base directory for source generated files.
Source file path ends up written in PDB and it may also be read from within the DLL via
CallerFileNameAttribute, after being transformed via path map.The current implementation does not work with path map though. Relative paths won't be translated via path map correctly since the map expects absolute paths as inputs.
One side effect of applying path map to paths on Windows is a normalization of directory separators (
\to/). If path map does not match the path when built on Windows\will remain in the path. If that path is read on Linux (e.g. via reading CallerFileNameAttribute value)PathAPIs will fail to recognize the directory separator.This will also cause unnecessary differences between builds on Windows and Linux.
Besides, it introduces additional inconsistencies throughout the system that need to be handled (e.g. in EnC).
Proposal
The relative paths of source generated files should be combined with the directory where other compiler outputs (e.g. xml doc comments, pdb, dll) are stored.
UPDATE - impact on reproducibility:
Additional problem occurs when source generator produces
#linedirectives that refer to additional files (e.g. .razor.g.cs files refer to .razor files).If the generator produced
#linedirectives with full paths then these paths will be correctly mapped via/pathmapwhen stored in the PDB. However, the generated source will also be stored in the PDB as is - i.e. with the full, unmapped paths in the#linedirectives. This creates a dependency on the directory from which the project is built and making the build non-reproducible. So the generator needs to emit#linedirectives with relative paths. How does the generator know the path of the generated file relative to the target path?Note: Razor source generator currently uses full paths and thus breaks reproducible builds.
UPDATE - impact on EnC/Hot Reload:
Combination of source generated files and file scoped types are causing issues with Hot Reload - e.g. #72331.
The IDE uses relative path for the source generated file, while the compiler is using absolute path.
Generated file class ends up having two different path hashes in metadata name.
Proposal
If/pathmapis specified the generator driver will apply it to all#linedirectives in the generated source before adding it to the resulting compilation.Use the same approach as #71879: Use
/generatedfilesoutor/outpath as base directory for source generated files.