File Storage
The default storage provider saves packages to the local file system or a network share.
Configuration
appsettings.json:
{
"Storage": {
"Type": "FileStorage",
"Path": "App_Data"
}
}
Program.cs:
builder.Services.AddNuGetPackageApi(options =>
{
options.AddFileStorage();
});
Path Options
The path can be:
1. Relative Path
Relative to the application directory:
{
"Storage": {
"Path": "App_Data"
}
}
This creates App_Data in the application's working directory.
2. Absolute Path
Full path to storage location:
Linux/macOS:
{
"Storage": {
"Path": "/var/packages"
}
}
Windows:
{
"Storage": {
"Path": "D:\\PackageStorage"
}
}
3. Network Share (Windows)
UNC path for shared storage:
{
"Storage": {
"Path": "\\\\server\\share\\packages"
}
}
Note: The application service account must have read/write permissions to the network share.
Directory Structure
File storage creates this structure:
App_Data/
packages/
newtonsoft.json/
12.0.1/
newtonsoft.json.12.0.1.nupkg
mypackage/
1.0.0/
mypackage.1.0.0.nupkg
symbols/
newtonsoft.json/
12.0.1/
newtonsoft.json.12.0.1.snupkg
Each package and version has its own directory for isolation.
Multi-Instance Deployments
For running multiple instances (load balancing):
- Use a network share or NAS accessible to all instances
- Configure permissions for the application service account
- Test write performance to ensure no bottlenecks
Example configuration:
{
"Storage": {
"Type": "FileStorage",
"Path": "\\\\nas-server\\nuget-packages"
}
}
Or use a cloud-based file share:
- Azure Files (SMB mount)
- AWS EFS (NFS mount)
Performance Considerations
Use SSD Storage
For best performance:
- Use SSD or NVMe drives for package storage
- Avoid spinning disks for production
- Monitor disk I/O and latency
Dedicated Storage
- Use separate storage from OS and application files
- Avoid shared storage with high I/O workloads
- Consider RAID for redundancy and performance
File System
Windows:
- Use NTFS with appropriate permissions
- Enable compression only if needed (trades CPU for disk space)
Linux:
- ext4 or XFS recommended
- Consider using
noatimemount option for better performance
Permissions
Windows
Grant the application service account:
- Modify permissions on the storage directory
- Include subdirectories and files
# Example: Grant IIS application pool identity
icacls "C:\PackageStorage" /grant "IIS APPPOOL\MyAppPool:(OI)(CI)M"
Linux
Set ownership and permissions:
sudo mkdir -p /var/packages
sudo chown -R www-data:www-data /var/packages
sudo chmod -R 755 /var/packages
Or for a specific application user:
sudo chown -R myapp:myapp /var/packages
Backup and Disaster Recovery
Backup Strategy
- Regular backups of the entire storage directory
- Incremental backups for efficiency
- Off-site backups for disaster recovery
Backup Methods
Windows:
- Windows Backup
- Robocopy scripts
- Third-party tools (Veeam, Acronis, etc.)
Linux:
- rsync to backup location
- tar/gzip archives
- Backup tools (Bacula, Amanda, etc.)
Example rsync backup:
rsync -av --delete /var/packages/ /backup/packages/
Restore
To restore:
- Stop the application
- Restore files to storage directory
- Verify permissions
- Start the application
Monitoring
Monitor these metrics:
- Disk space usage: Alert when nearing capacity
- Disk I/O: Monitor read/write latency
- File count: Large numbers of small files can impact performance
Disk Space Alerts
Set up alerts when disk usage exceeds thresholds:
- Warning: 75% full
- Critical: 90% full
Maintenance
Cleanup
Periodically clean up:
- Unlisted packages (if allowed)
- Old prerelease versions
- Orphaned files
Defragmentation (Windows)
For spinning disks, periodically defragment:
Optimize-Volume -DriveLetter D -Defrag -Verbose
Not needed for SSDs (can reduce lifespan).
Troubleshooting
"Access Denied" Errors
Check:
- Application service account has permissions
- Antivirus is not blocking file access
- Parent directory permissions are correct
Slow Performance
Consider:
- Upgrade to SSD storage
- Check for disk I/O bottlenecks
- Reduce file system overhead (fewer directories/files)
- Use cloud storage for better scalability
Network Share Issues
- Verify network connectivity
- Check share permissions
- Test write speed from application server
- Consider increasing network bandwidth
When to Use File Storage
Good for:
- Development and testing
- Small deployments (< 100 packages)
- Single-instance applications
- Internal networks with fast storage
Not recommended for:
- Large-scale deployments
- Multi-region scenarios
- High-traffic feeds
- Environments requiring cloud-native features