Skip to content

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

Open

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();
}

Activity

  1. changed the title [-]Connection string is not availalbe when using the new simplified build folder structure[/-] [+]Connection string is not available when using the new simplified build folder structure[/+] on Jan 8, 2026
  2. dougwaldron commented on Jan 8, 2026

    @dougwaldron
    Author

    After a little more testing, I've figured out that EfCore.TestSupport works if the appsettings.json file is located in the root of the new folder structure:

    📁 artifacts                 ← TestSupport looks for "appsettings.json" here.
        └──📂 <Type of output>
            └──📂 <Project name>
                └──📂 <Pivot>    ← Testing assembly is here.
    

    I can work around this issue for now by copying the settings file to the root artifacts folder, but this is counter to expectations and could result in a conflict if more than one test project exists with different settings files.

  3. dougwaldron commented on Jan 8, 2026

    @dougwaldron
    Author

    For anyone else with this issue, adding something like the following to your test's csproj file will copy the settings file where you need it, but you might have to adjust the path depending on your project folder layout.

        <Target Name="CopySettingsFile" AfterTargets="AfterBuild">
            <Copy SourceFiles="appsettings.json" 
                  DestinationFolder="$(MSBuildThisFileDirectory)../../artifacts"/>
        </Target>

    On the other hand, if this issue can be fixed, the following would work instead, and wouldn't depend on the project layout.

        <ItemGroup>
            <None Update="appsettings.json" CopyToOutputDirectory="Always" />
        </ItemGroup>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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