[Repo Assist] feat: add appsettings.json support to DesignTimeConnectionString (Closes #370)#468
Draft
github-actions[bot] wants to merge 2 commits intomasterfrom
Conversation
#370) - ReadFromConfig now auto-discovers appsettings.json when no app.config/web.config is present, enabling ASP.NET Core projects to resolve named connection strings at design time. - Explicit appsettings.json files are also accepted as the ConfigFile parameter. - Improved error message when no config file is found, mentioning appsettings.json. - Added TryReadFromAppSettings helper (public for testability) using a regex-based JSON parser — no new dependencies required. - Added tests for auto-discovery, explicit file, missing name, and error messages. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is a draft PR from Repo Assist.
Summary
Adds support for reading named connection strings from
appsettings.jsonat design time, enabling ASP.NET Core projects to use thename=...connection string syntax with this type provider.Problem
Currently
DesignTimeConnectionString.ReadFromConfigonly searches forapp.configandweb.config. ASP.NET Core projects that store connection strings inappsettings.jsonget a build-time error like "Cannot find either App.config or Web.config" even though their connection string is properly defined.Changes
src/SqlClient.DesignTime/DesignTimeConnectionString.fsapp.config/web.configis present,ReadFromConfignow triesappsettings.jsonandappsettings.Development.jsonin the resolution folder. The standard ASP.NET CoreConnectionStringssection is read:{ "ConnectionStrings": { "MyDb": "Server=.;Database=MyApp;Integrated Security=True" } }ConfigFile = "appsettings.json"is now supported alongside XML config files.appsettings.jsonand theConfigFileparameter.System.Text.RegularExpressions(BCL), no additional NuGet packages.ReadFromXmlConfighelper to reduce duplication.tests/SqlClient.DesignTime.Tests/DesignTimeConnectionStringTests.fs+appsettings.jsonAdded tests covering:
TryReadFromAppSettingsfinds / misses / gracefully handles missing filesappsettings.jsonasfileName"appsettings.json"Limitation
The runtime connection string lookup still uses
System.Configuration.ConfigurationManager, which doesn't readappsettings.json. In ASP.NET Core at runtime, inject the connection string fromIConfigurationvia theconnectionconstructor parameter instead.Test Status
Build and unit tests could not be run in this environment (paket restore unavailable — infrastructure-only limitation). The changes are syntactically straightforward and logically extend the existing
ReadFromConfigwithout modifying any existing code paths.