Core abstractions and download logic for DIHOR RepoFiles.
$ dotnet add package DIHOR.RepoFilesDIHOR RepoFiles is a small set of NuGet packages for managing files stored in a repository using a JSON manifest.
DIHOR.RepoFiles (core)DIHOR.RepoFiles.GitHub (GitHub provider)DIHOR.RepoFiles.Configuration (IConfiguration binding)DIHOR.RepoFiles.Cli (CLI tool)dotnet add package DIHOR.RepoFiles
dotnet add package DIHOR.RepoFiles.GitHub
dotnet add package DIHOR.RepoFiles.Configuration
dotnet tool install -g DIHOR.RepoFiles.Cli
manifest.json is a JSON array of entries:
[
{
"filename": "data.db",
"url": "https://raw.githubusercontent.com/owner/repo/main/data.db",
"size": 123456,
"modifydate": "2024-01-01T12:00:00Z",
"metadata": "{\"minAppVersion\":\"1.2.3\",\"note\":\"Optional note\"}"
}
]
Store extra fields inside metadata as a serialized JSON string. To deserialize it without manual parsing:
public sealed class FileMetadata
{
public string? MinAppVersion { get; set; }
}
var entries = await client.GetManifestAsync<FileMetadata>();
var minVersion = entries[0].Metadata?.MinAppVersion;
{
"RepoFiles": {
"Provider": "GitHub",
"GitHub": {
"Owner": "your-org",
"Repository": "your-repo",
"Branch": "main",
"ManifestPath": "manifest.json"
},
"GitHubPublisher": {
"Owner": "your-org",
"Repository": "your-repo",
"Branch": "main",
"Token": "github_pat_...",
"CommitterName": "RepoFiles Bot",
"CommitterEmail": "bot@your-org.com"
},
"Download": {
"TargetDirectory": "Data",
"SkipIfSameSizeAndDate": true,
"Overwrite": false
}
}
}
using DIHOR.RepoFiles;
using DIHOR.RepoFiles.GitHub;
using DIHOR.RepoFiles.GitHub.Providers;
var provider = new GitHubRepositoryProvider(new GitHubRepositoryOptions
{
Owner = "your-org",
Repository = "your-repo",
Branch = "main",
ManifestPath = "manifest.json"
});
var client = new RepoClient(provider);
await client.DownloadToDirectoryAsync("data.db", "Data");
GitHubRepositoryPublisher uses the GitHub Contents API and requires a PAT with contents:write.
using DIHOR.RepoFiles.GitHub;
using DIHOR.RepoFiles.GitHub.Publishers;
var publisher = new GitHubRepositoryPublisher(new GitHubPublisherOptions
{
Owner = "your-org",
Repository = "your-repo",
Branch = "main",
Token = "github_pat_...",
CommitterName = "RepoFiles Bot",
CommitterEmail = "bot@your-org.com"
});
await publisher.PublishAsync("Data/manifest.json", "Distribution/manifest.json", "Update manifest");
DI registration:
services.AddRepoFilesGitHubPublisher(options =>
{
options.Owner = "your-org";
options.Repository = "your-repo";
options.Branch = "main";
options.Token = "github_pat_...";
});
dihor-repofiles list
dihor-repofiles pull data.db --dest Data
The CLI reads appsettings.json from the current directory (or pass --config).
dotnet pack -c Release
Push the packages to NuGet.org (repeat for each project output folder):
dotnet nuget push "src/DIHOR.RepoFiles/bin/Release/*.nupkg" -k <NUGET_API_KEY> -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push "src/DIHOR.RepoFiles.GitHub/bin/Release/*.nupkg" -k <NUGET_API_KEY> -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push "src/DIHOR.RepoFiles.Configuration/bin/Release/*.nupkg" -k <NUGET_API_KEY> -s https://api.nuget.org/v3/index.json --skip-duplicate
dotnet nuget push "src/DIHOR.RepoFiles.Cli/bin/Release/*.nupkg" -k <NUGET_API_KEY> -s https://api.nuget.org/v3/index.json --skip-duplicate
Tip: store the key in an environment variable (NUGET_API_KEY) or use dotnet nuget setapikey.