mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-12 20:33:48 +00:00
Improved dev experience & allow native .NET debugging (#460)
This commit is contained in:
1 parent
c0cf620fe3
commit
4ca1fd54d9
7 files changed
+139
-42
No files matched your search
@@ -0,0 +1,41 @@
|
||||
#if DEBUG
|
||||
using System.Text;
|
||||
|
||||
namespace AIStudio.Tools;
|
||||
|
||||
/// <summary>
|
||||
/// Read environment variables for the application from an .env file.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// We consider this feature a security issue. Therefore, it is only
|
||||
/// available in DEBUG mode. To ensure this, we remove the code
|
||||
/// from any release build.
|
||||
/// </remarks>
|
||||
public static class EnvFile
|
||||
{
|
||||
public static async Task Apply(string filePath)
|
||||
{
|
||||
if(!File.Exists(filePath))
|
||||
{
|
||||
Console.WriteLine($"Error: The .env file '{filePath}' does not exist.");
|
||||
return;
|
||||
}
|
||||
|
||||
var lines = await File.ReadAllLinesAsync(filePath, Encoding.UTF8);
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line) || line.Trim().StartsWith('#'))
|
||||
continue;
|
||||
|
||||
var parts = line.Split(['='], 2);
|
||||
if (parts.Length != 2)
|
||||
continue;
|
||||
|
||||
var key = parts[0].Trim();
|
||||
var value = parts[1].Trim();
|
||||
|
||||
Environment.SetEnvironmentVariable(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user