Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 18, 2026

The CLI was manually parsing .env files to read OpenAI settings; align with standard .NET configuration/user secrets instead.

  • Configuration source: use ConfigurationBuilder with user secrets and environment variables; remove custom .env parsing.
  • CLI project: add UserSecretsId and configuration package references to support standard secret management.

Example usage:

var configuration = new ConfigurationBuilder()
    .AddUserSecrets<Program>(optional: true)
    .AddEnvironmentVariables()
    .Build();

var apiKey = configuration["OPENAI_API_KEY"];
Original prompt

I see that the AI tried to replicate Go .env files

var envPath = Path.Combine(Directory.GetCurrentDirectory(), ".env");
if (File.Exists(envPath))
{
try
{
foreach (var line in File.ReadAllLines(envPath))
{
var trimmed = line.Trim();
if (string.IsNullOrEmpty(trimmed) || trimmed.StartsWith('#'))
continue;

                var parts = trimmed.Split('=', 2);
                if (parts.Length == 2)
                {
                    Environment.SetEnvironmentVariable(parts[0].Trim(), parts[1].Trim());
                }
            }
        }
        catch (Exception ex)
        {
            await stderr.WriteLineAsync($"failed to load .env: {ex.Message}");
            return 1;
        }
    }

    var defaultModel = Environment.GetEnvironmentVariable("OPENAI_MODEL") ?? "gpt-4o";
    var defaultReasoning = Environment.GetEnvironmentVariable("OPENAI_REASONING_EFFORT") ?? "";
    var defaultBaseURL = Environment.GetEnvironmentVariable("OPENAI_BASE_URL") ?? "";

    string? model = null, reasoningEffort = null, promptAugmentation = null, baseURL = null, prompt = null, research = null;

just make it use dotnet secrets or something more standard


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Implement loading of .env files for configuration Replace ad-hoc .env loading with standard configuration Jan 18, 2026
Copilot AI requested a review from rogeralsing January 18, 2026 11:36
This was referenced Jan 21, 2026
Copy link
Contributor

@rogeralsing rogeralsing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup: replacing the ad-hoc parser with + user-secrets/env vars is much more idiomatic.

A couple small follow-ups to consider:

  • : the error message still says but it can now come from user-secrets too; suggest wording like .
  • This change removes support entirely; if that’s intentional, a short README note (how to set via ) would prevent confusion.

FYI: I built the branch locally with MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. successfully (existing warnings only).

Copy link
Contributor

@rogeralsing rogeralsing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleanup: replacing the ad-hoc .env parser with ConfigurationBuilder + user-secrets/env vars is much more idiomatic.

A couple small follow-ups to consider:

  • Program.cs: the error message still says OPENAI_API_KEY must be set in the environment. but it can now come from user-secrets too; suggest wording like must be configured (env var or user-secrets).
  • This change removes .env support entirely; if that’s intentional, a short README note (how to set via dotnet user-secrets set OPENAI_API_KEY ... --project src/Asynkron.Agent.Cli) would prevent confusion.

FYI: I built the branch locally with dotnet build -c Release successfully (existing warnings only).

@rogeralsing
Copy link
Contributor

Housekeeping: my first review ended up mangled due to shell quoting/backticks. Please ignore that one; the following review (with proper Markdown) has the actual feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants