Skip to content

Connection string is not available when using the new simplified build folder structure #62

@dougwaldron

Description

@dougwaldron

.NET 8 introduced a new simplified output path and folder structure for build outputs. The new format is opt-in by adding the following to the Directory.Build.props file:

<PropertyGroup>
  <UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>

When I enable this in my projects, I start getting the error:

System.InvalidOperationException : You are missing a connection string of name 'UnitTestConnection' in the appsettings.json file.

This is the only issue I've encountered with the new setting. I've confirmed that the appsettings.json file is copied to the correct output directory alongside my testing project assembly. I can manually load the settings file as shown below, and the following test passes, but my tests that use EfCore.TestSupport don't seem to load any of the settings.

[Test]
public void AppSettingsIsLoaded()
{
    var config = new ConfigurationBuilder()
        .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
        .AddJsonFile("appsettings.json", optional: false)
        .Build();

    var value = config["Test"];
    value.Should().NotBeNull();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions