Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Samples/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=BAR
1 change: 1 addition & 0 deletions src/Samples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{ "user", "What's Tesla stock worth today? Search X and the news for latest info." },
};

// Env supports .env as well as all standard .NET configuration sources
var grok = new GrokClient(Env.Get("XAI_API_KEY")!, new GrokClientOptions()
.UseJsonConsoleLogging(new() { WrapLength = 80 }));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Weaving;

class ConsoleInitializer
class AppInitializer
{
#pragma warning disable CA2255 // The 'ModuleInitializer' attribute should not be used in libraries
[ModuleInitializer]
Expand All @@ -13,5 +13,13 @@ public static void Init()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
Console.InputEncoding = Console.OutputEncoding = Encoding.UTF8;

// Load environment variables from .env files in current dir and above.
DotNetEnv.Env.TraversePath().Load();

// Load environment variables from user profile directory.
var userEnv = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".env");
if (File.Exists(userEnv))
DotNetEnv.Env.Load(userEnv);
}
}
1 change: 1 addition & 0 deletions src/Weaving/Weaving.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.6" />
<PackageReference Include="NuGetizer" Version="1.2.4" PrivateAssets="all" />
</ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/Weaving/Weaving.props
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

<ItemGroup>
<AssemblyMetadata Include="MSBuildProjectName" Value="$(MSBuildProjectName)" />
<None Update=".env" CopyToOutputDirectory="PreserveNewest" CopyToPublishDirectory="Never" />
</ItemGroup>

</Project>
15 changes: 15 additions & 0 deletions src/Weaving/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ AnsiConsole.MarkupLine($":robot: {response.Text}");
> The most useful namespaces and dependencies for developing Microsoft.Extensions.AI-
> powered applications are automatically referenced and imported when using this package.

## Configuration / Environment Variables

The `Env` class provides access to the following variables/configuration automatically:

* `.env` files: in local and parent directories
* `~/.env` file: in the user's home directory (`%userprofile%\.env` on Windows)
* All default configuration sources from [App Builder](https://learn.microsoft.com/en-us/dotnet/core/extensions/generic-host?tabs=appbuilder#host-builder-settings):
* Environment variables prefixed with DOTNET_.
* Command-line arguments.
* appsettings.json.
* appsettings.{Environment}.json.
* Secret Manager when the app runs in the Development environment.
* Environment variables.
* Command-line arguments.

<!-- #content -->
<!-- include https://github.com/devlooped/sponsors/raw/main/footer.md -->
<!-- exclude -->
Loading