最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - c# Environment.GetFolderPath for Environment.SpecialFolder.ApplicationData not respecting HOME - Stack Overflow

programmeradmin4浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论