I have a CI/CD build environment that sandboxes the filesystem to /tmp. Binaries running in the sandbox do not have access to HOME or other directories. HOME is set to /tmp, which works for most apps but not for dotnet apps that rely on Environment.SpecialFolder.ApplicationData.
As a test, I created a simple C# program that prints out the location of Environment.SpecialFolder.ApplicationData
and Environment.SpecialFolder.UserProfile
.
Console.WriteLine("UserProfile: " + Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
Console.WriteLine("ApplicationData: " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData));
Console.WriteLine("LocalApplicationData:" + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
When I dotnet run
this program, it correctly outputs the following:
UserProfile: /Users/mike
ApplicationData: /Users/mike/Library/Application Support
LocalApplicationData:/Users/mike/Library/Application Support
When I run this program in an environment where $HOME
is set to /tmp
(as is the case on my CI/CD build system), I get the following
mike@mac MyConsoleApp % bash
bash-3.2$ export HOME=/tmp
bash-3.2$ dotnet run
UserProfile: /tmp
ApplicationData: /Users/mike/Library/Application Support
LocalApplicationData:/Users/mike/Library/Application Support
The UserProfile
correctly reflect /tmp
, but the other special folders like ApplicationData
and LocalApplicationData
still reference /Users/mike
. I would expect these folders to be relative to the user's home.
I tried setting DOTNET_CLI_HOME
to /tmp
, but that didn't help.
Without changing my C# code, what is the proper way to tell dotnet that ApplicationData should be relative to HOME?