ToolBX.ProjectMaster 2.2.0

dotnet add package ToolBX.ProjectMaster --version 2.2.0
NuGet\Install-Package ToolBX.ProjectMaster -Version 2.2.0
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="ToolBX.ProjectMaster" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ToolBX.ProjectMaster --version 2.2.0
#r "nuget: ToolBX.ProjectMaster, 2.2.0"
#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.
// Install ToolBX.ProjectMaster as a Cake Addin
#addin nuget:?package=ToolBX.ProjectMaster&version=2.2.0

// Install ToolBX.ProjectMaster as a Cake Tool
#tool nuget:?package=ToolBX.ProjectMaster&version=2.2.0

ProjectMaster

ProjectMaster

Provides a base class to format and access application data paths in an easy and straightforward way.

This package merely combines your data paths with your application name in a reusable class so that you don't have to repeat yourself.

//Instead of doing this
var path = Path.Combine(Environment.SpecialFolder.LocalApplicationData, "My Application");

//You can just do this
var path = _projectEnvironment.LocalUser;

Getting started

Setup

ProjectMaster works with DI so you're going to have to use the following method wherever you inject things to get it to work:

services.AddNetAbstractions();

You can skip the above line if you are already using either ToolBX.AutoInject or ToolBX.AssemblyInitializer.

Creating your own ProjectEnvironment class

public class MyProjectEnvironment : ProjectEnvironment
{
    //Organization is optional and can be left blank
    protected override string OrganizationName => "My organization";

    //Project is mandatory and your ProjectEnvironment class WILL throw if it is omitted or left blank
    protected override string ProjectName => "My project";

    public DummyProjectEnvironment(IServiceProvider serviceProvider) : base(serviceProvider)
    {
    }
}

You can (should) take advantage of the AutoInject library this way but it is entirely up to you :

//It will automatically link to IProjectEnvironment so you don't even need to make your own interface!
[AutoInject]
public class MyProjectEnvironment : ProjectEnvironment
{
    ...
}

Otherwise, you can use the following to inject it manually :

services.AddSingleton<IProjectEnvironment, MyProjectEnvironment>();

How do I use it?

Once you have your custom class and it is injected in your code :

private readonly IProjectEnvironment _projectEnvironment;

public SomeClass(IProjectEnvironment projectEnvironment)
{
    _projectEnvironment = projectEnvironment;
}

public void Something()
{
    //On windows would return something like : "c:/Users/Default/AppData/Local/My organization/My project/"
    var path = _projectEnvironment.AllUsers;

    //"c:/Users/YourName/AppData/Local/My organization/My project/"
    path = _projectEnvironment.LocalUser;

    //"c:/Users/YourName/AppData/Roaming/My organization/My project/"
    path = _projectEnvironment.RoamingUser;

    //"c:/Users/YourName/AppData/Local/Temp/My organization/My project/"
    path = _projectEnvironment.TemporaryFiles;
}

I'm making a video game : where should save files go?

There is not a one-size fits all response to this. Some put it in the local user's app data but others put it in the user's Documents folder. I even hear that it's not uncommon to keep save files in the game's installation folder.

Steam seems to like putting it in 'Documents/My Games/Game name/'.

Personally, I put it in the roaming user's folder. This approach should work seamlessly across most (if not all) modern operating systems.

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in 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
2.2.0 106 1/13/2024
2.2.0-beta1 74 1/7/2024
2.0.2 139 6/19/2023
2.0.1 179 4/27/2023
2.0.0 304 11/12/2022
2.0.0-beta1 114 10/7/2022
1.0.1 395 10/7/2022
1.0.0 414 6/22/2022