Skip to content

Testing: set launch profile name based on target AppHost#4287

Merged
ReubenBond merged 1 commit intomainfrom
rebond/testing-launch-profile-and-content-root
Jun 4, 2024
Merged

Testing: set launch profile name based on target AppHost#4287
ReubenBond merged 1 commit intomainfrom
rebond/testing-launch-profile-and-content-root

Conversation

@ReubenBond
Copy link
Copy Markdown
Member

@ReubenBond ReubenBond commented May 24, 2024

Also: set AppHost ContentRootPath.

This adds a DefaultLaunchProfileAnnotation to all projects where the launch profile is not explicitly set, which lets us override it via config (not just process-wide env var). This lets us set this value on a per-app-host basis in tests, which we cannot do using env vars (they are global state).

Fixes #4286
Fixes #4282

Possibly fixes #4274

cc @DamianEdwards

Microsoft Reviewers: Open in CodeFlow

@ghost ghost added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label May 24, 2024
private static bool TrySelectLaunchProfileFromEnvironment(ProjectResource projectResource, [NotNullWhen(true)] out string? launchProfileName)
private static bool TrySelectLaunchProfileFromDefaultAnnotation(ProjectResource projectResource, [NotNullWhen(true)] out string? launchProfileName)
{
var launchProfileEnvironmentVariable = Environment.GetEnvironmentVariable("DOTNET_LAUNCH_PROFILE");
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

var appHostLaunchSettings = GetLaunchSettings(appHostProjectPath);
if (appHostLaunchSettings?.Profiles.FirstOrDefault().Key is { } profileName)
{
additionalConfig["AppHost:DefaultLaunchProfileName"] = profileName;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wonder whether we should start putting these keys in constants somewhere.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We probably should do a sweep of them at some point

Comment thread src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs Outdated
[LocalOnlyTheory]
[InlineData(false)]
[InlineData(true)]
public async Task SelectsFirstLaunchProfile(bool genericEntryPoint)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we be adding an API for selecting the launch profile when using the test builder?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Perhaps in a different PR?

Comment thread src/Aspire.Hosting.Testing/DistributedApplicationFactory.cs
@ReubenBond ReubenBond force-pushed the rebond/testing-launch-profile-and-content-root branch 2 times, most recently from 0bd82f2 to 1a86ece Compare May 31, 2024 19:50
@ReubenBond ReubenBond force-pushed the rebond/testing-launch-profile-and-content-root branch from 1a86ece to 40554cd Compare June 4, 2024 14:12
@ReubenBond ReubenBond force-pushed the rebond/testing-launch-profile-and-content-root branch from 40554cd to c4a92fe Compare June 4, 2024 14:13
@ReubenBond ReubenBond merged commit 51ff4e3 into main Jun 4, 2024
@ReubenBond ReubenBond deleted the rebond/testing-launch-profile-and-content-root branch June 4, 2024 15:28
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication

Projects

None yet

3 participants