TedToolkit.FileSystem.ProjectPaths 2026.9.11.1

dotnet add package TedToolkit.FileSystem.ProjectPaths --version 2026.9.11.1
                    
NuGet\Install-Package TedToolkit.FileSystem.ProjectPaths -Version 2026.9.11.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TedToolkit.FileSystem.ProjectPaths" Version="2026.9.11.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TedToolkit.FileSystem.ProjectPaths" Version="2026.9.11.1" />
                    
Directory.Packages.props
<PackageReference Include="TedToolkit.FileSystem.ProjectPaths" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TedToolkit.FileSystem.ProjectPaths --version 2026.9.11.1
                    
#r "nuget: TedToolkit.FileSystem.ProjectPaths, 2026.9.11.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TedToolkit.FileSystem.ProjectPaths@2026.9.11.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TedToolkit.FileSystem.ProjectPaths&version=2026.9.11.1
                    
Install as a Cake Addin
#tool nuget:?package=TedToolkit.FileSystem.ProjectPaths&version=2026.9.11.1
                    
Install as a Cake Tool

TedToolkit.FileSystem.ProjectPaths

TedToolkit.FileSystem.ProjectPaths generates strongly typed DirectoryPath and FilePath members for the files and directories you explicitly select from the current Git work tree.

It provides compile-time path access without hard-coding paths throughout an application:

var repository = ProjectPaths.Git;
var project = ProjectPaths.Project;
var appProject = ProjectPaths.src.App.App_csproj;

Only paths selected by evaluated TedToolkitFileSystemPath items are generated. Selecting a directory never implicitly generates its children.

Requirements

  • The project must be inside a Git work tree.
  • The git executable must be available on the build machine's PATH.
  • The generated code uses TedToolkit.FileSystem.DirectoryPath and TedToolkit.FileSystem.FilePath; this dependency is included by the package.

Install

Add the package to the project that needs the generated paths:

<PackageReference Include="TedToolkit.FileSystem.ProjectPaths" Version="*" PrivateAssets="all" />

Select paths

Add TedToolkitFileSystemPath items for the files and directories that should become available through ProjectPaths. These are standard MSBuild items: relative paths are resolved from the project directory, and MSBuild expands Include, Exclude, Update, *, ?, and ** before the source generator runs.

For repository-wide selections, place the items in the repository root Directory.Build.props and anchor them with $(MSBuildThisFileDirectory):

<ItemGroup>
  
  <TedToolkitFileSystemPath Include="$(MSBuildThisFileDirectory)*.slnx" Kind="File" />

  
  <TedToolkitFileSystemPath Include="$(MSBuildThisFileDirectory)**/*.csproj"
                            Exclude="$(MSBuildThisFileDirectory)**/bin/**/*;$(MSBuildThisFileDirectory)**/obj/**/*"
                            Kind="File" />

  
  <TedToolkitFileSystemPath Include="$(MSBuildThisFileDirectory)src/App/Assets" Kind="Directory" />
</ItemGroup>

Kind accepts File, Directory, or Any; it defaults to Any. Use File or Directory when the expected path type is known.

MSBuild expands file globs into concrete items before generation:

Token Matches
* Any characters within one path segment. src/App/*.json does not match files in child directories.
? One character within one path segment.
** Zero or more directory segments. src/App/**/*.json matches both src/App/appsettings.json and src/App/Settings/feature.json.

Directory items must name a concrete directory; directory glob expansion is not provided. A selected directory generates its Directory property, but never generates its files or child directories unless files are selected by another item.

The generator consumes only the concrete paths selected by MSBuild. It does not scan the repository or implement a second glob matcher.

Name is optional and applies only to files. Use it to override a generated file member name when a file name would be unclear or conflicts with another file member:

<TedToolkitFileSystemPath Include="src/App/appsettings.Development.json"
                          Kind="File"
                          Name="DevelopmentSettings" />

When a file came from a glob, use standard MSBuild Update to set its name:

<TedToolkitFileSystemPath Update="$(MSBuildThisFileDirectory)src/App/appsettings.Development.json"
                          Name="DevelopmentSettings" />

Migrating from 1.x

Version 1.x treated item values as Git-work-tree-relative patterns and required wildcard escaping. Version 2.0 uses native MSBuild item semantics.

Move repository-wide declarations to the root Directory.Build.props and replace escaped patterns:


<TedToolkitFileSystemPath Include="$([MSBuild]::Escape('\*.slnx'))" Kind="File" />


<TedToolkitFileSystemPath Include="$(MSBuildThisFileDirectory)*.slnx" Kind="File" />

Apply the same prefix to recursive patterns and exact repository-root paths. Consumers that cannot migrate immediately can remain on the latest 1.x package.

Generated API

Every project receives one generated ProjectPaths class in the project's root namespace:

public static class ProjectPaths
{
    public static DirectoryPath Git { get; }

    public static FilePath Project { get; }
}
  • ProjectPaths.Git is the Git work tree root.
  • ProjectPaths.Project is the .csproj file that references this package.
  • Each generated directory is a static class with a Directory: DirectoryPath property.
  • Each generated file is a FilePath property.

For the preceding configuration, usage looks like this:

var assetsDirectory = ProjectPaths.src.App.Assets.Directory;
var appProject = ProjectPaths.src.App.App_csproj;

The generated ProjectPaths class is placed in the project's RootNamespace. Import that namespace before using it from another namespace:

using MyProject;

var appProject = ProjectPaths.src.App.App_csproj;

Generated XML documentation contains the corresponding full path, so the path is visible in IntelliSense.

Member names

Directory names preserve their original casing. File names also preserve casing, while characters that are not valid in C# identifiers are replaced with one underscore. Consecutive invalid characters produce only one underscore.

Path name Generated member name
appsettings.Development.json appsettings_Development_json
my file-name.json my_file_name_json
2026-report.json _2026_report_json
class.json _class_json

If two selected files produce the same member name, the build reports TTFS002. Set Name on one of the file items to resolve it.

Diagnostics

Id Meaning
TTFS001 The project is not inside a Git work tree, or Git could not provide its root.
TTFS002 Two selected paths produce the same generated member name.
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.9.11.1 93 9/11/2026
2026.8.3 111 8/3/2026
2026.7.15 109 7/15/2026
2.0.0 86 9/11/2026