Sourcy is a Source Generator that gives you static compile-time properties to file paths within your repository.
This can be useful for things like tests, scripts or pipelines where you may need to locate something from the file system.
This can avoid having to deal with relative paths, or defining absolute paths which may change machine-to-machine.
After installing the Sourcy package(s) you want, properties can be found within the Sourcy
namespace. So just start typing Sourcy.
and your IDE should help you with the rest.
Currently Sourcy has 4 packages:
Attempts to find your Git directory by parsing the result of git rev-parse --show-toplevel
Searches for Projects with a .csproj
or .fsproj
extension
Searches for Solutions with a .sln
, .slnx
or .slnf
extension
Locates Node projects within your repository by looking for a package-lock.json
or yarn.lock
file
Locates Dockerfile
s within your repository
For files you are given a FileInfo
object, and for directories a DirectoryInfo
object. This allows you to easy call things like EnumerateFiles
on.
e.g.
var testResultsReport = Sourcy.Git.RootDirectory
.EnumerateFiles("*.trx", SearchOption.AllDirectories)
.First();