Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aspire.Hosting.Testing should populate DOTNET_LAUNCH_PROFILE #5093

Closed
eerhardt opened this issue Jul 26, 2024 · 3 comments · Fixed by #7363 or #7447
Closed

Aspire.Hosting.Testing should populate DOTNET_LAUNCH_PROFILE #5093

eerhardt opened this issue Jul 26, 2024 · 3 comments · Fixed by #7363 or #7447
Assignees
Labels
area-app-testing Issues pertaining to the APIs in Aspire.Hosting.Testing
Milestone

Comments

@eerhardt
Copy link
Member

When Aspire.Hosting.Testing's DistributedApplicationTestingBuilder creates and builds a DistributedApplicationBuider, it should pass in the DOTNET_LAUNCH_PROFILE configuration setting so AppHost code can switch off the launch profile, like documented in https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_launch_profile.

We use this in our samples here:

https://github.com/dotnet/aspire-samples/blob/08c14cdc112c74811c44976064b8d85e39e8bd93/samples/AspireWithNode/AspireWithNode.AppHost/Program.cs#L16-L20

But that check doesn't work when running in an Aspire.Hosting.Testing test because that configuration setting isn't being populated by the testing infrastructure.

cc @ReubenBond @mitchdenny @radical

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Jul 26, 2024
@eerhardt eerhardt added area-app-testing Issues pertaining to the APIs in Aspire.Hosting.Testing and removed area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication labels Jul 26, 2024
@davidfowl davidfowl added the bug label Sep 7, 2024
@mackie1001
Copy link

Interested in the outcome of this.

I'm looking to feed in some configuration from test host to the underlying Aspire host as we have various options that are controlled via launchProfile environment vars when running the host directly.

Being able to set the launch profile (it appears no launch profile is used when using DistributedApplicationTestingBuilder) or directly setting environment vars or even injecting into the inner builder's configuration collection directly would be very handy.

As a workaround we've used the command line args directly and ensured that they've loaded into the ambient configuration in the Aspire host. As long as we use the .Net configuration stuff and not environment variables directly this works in all scenarios.

Test project:

        //xunit IAsyncLifetime
        public async Task InitializeAsync()
        {
            string[] args = 
            [
                "USE_EMULATORS=False",
                "USE_USER_SECRETS=True",
                "PROVISION_DATABASES_BEFORE_START=False"
            ];

            var builder = await DistributedApplicationTestingBuilder
                .CreateAsync<Projects.Membership_Aspire_Host>(args, (options, builderSettings) => { });

            AspireHost = await builder.BuildAsync();
            await AspireHost.StartAsync();
        }

Aspire host:

        //Aspire.AppHost/Program.cs
        private static async Task Main(string[] args)
        {
            var options = new DistributedApplicationOptions() { Args = args }; //Passing args here does not seem to init builder.Configuration
            var builder = DistributedApplication.CreateBuilder(options);
            builder.Configuration.AddCommandLine(args); //This does work and make the args passed from the text fixture available
            ...
            var useEmulators = builder.Configuration["USE_EMULATORS"] == "True";

@joperezr joperezr added the untriaged New issue has not been triaged label Oct 15, 2024
@davidfowl davidfowl removed the bug label Oct 16, 2024
@davidfowl davidfowl removed the untriaged New issue has not been triaged label Jan 10, 2025
@davidfowl davidfowl assigned davidfowl and ReubenBond and unassigned davidfowl Jan 10, 2025
@joperezr joperezr added the untriaged New issue has not been triaged label Jan 13, 2025
@davidfowl davidfowl removed the untriaged New issue has not been triaged label Jan 15, 2025
@davidfowl davidfowl added this to the 9.1 milestone Jan 15, 2025
@ReubenBond
Copy link
Member

PR here #7363

@ReubenBond
Copy link
Member

Reopening since we reverted #7371 (due to unrelated test infra issues)

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