├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── CODE-OF-CONDUCT.md ├── CONTRIBUTING.md ├── License.txt ├── MicrosoftConfigurationBuilders.msbuild ├── MicrosoftConfigurationBuilders.sln ├── README.md ├── SECURITY.md ├── azure-pipeline └── azure-pipeline.yml ├── build.cmd ├── clean.cmd ├── docs ├── CustomConfigBuilders.md ├── FAQ.md ├── Intro.md ├── KeyValueConfigBuilders.md └── SectionHandlers.md ├── samples ├── SampleConsoleApp │ ├── App.config │ ├── ClientSettings.Designer.cs │ ├── ClientSettings.settings │ ├── Program.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ └── SampleConsoleApp.csproj ├── SampleItems │ ├── KeyPerFileRoot │ │ ├── KPF-Setting1 │ │ ├── KPF-Setting2 │ │ ├── SubFeatures │ │ │ ├── KPF-SubFeatureA │ │ │ ├── KPF-SubFeatureB │ │ │ └── ignore.KPF-SubFeatureC │ │ └── ignore.KPF-Setting3 │ └── secrets.xml ├── SampleWebApp │ ├── App_Data │ │ └── settings.json │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SampleWebApp.csproj │ ├── Web.config │ └── default.aspx ├── SampleWebJob │ ├── Functions.cs │ ├── Program.cs │ ├── SampleWebJob.csproj │ ├── Settings.job │ ├── app.config │ └── appsettings.json └── SamplesLib │ ├── ClientSettingsSectionHandler.cs │ ├── ExpandWrapper.cs │ ├── Properties │ └── AssemblyInfo.cs │ └── SamplesLib.csproj ├── src ├── 35MSSharedLib1024.snk ├── Azure │ ├── Azure.csproj │ ├── AzureKeyVaultConfigBuilder.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── AzureAppConfig │ ├── AzureAppConfig.csproj │ ├── AzureAppConfigurationBuilder.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Base │ ├── Base.csproj │ ├── KeyValueConfigBuilder.cs │ ├── KeyValueEnabled.cs │ ├── KeyValueExceptions.cs │ ├── KeyValueMode.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── RecursionGuard.cs │ ├── SectionHandler.cs │ ├── SectionHandlerSection.cs │ └── Utils.cs ├── Environment │ ├── Environment.csproj │ ├── EnvironmentConfigBuilder.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── Json │ ├── Json.csproj │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── SimpleJsonConfigBuilder.cs │ └── SimpleJsonConfigBuilderMode.cs ├── KeyPerFile │ ├── KeyPerFile.csproj │ ├── KeyPerFileConfigBuilder.cs │ └── Properties │ │ └── AssemblyInfo.cs ├── UserSecrets │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── UserSecrets.csproj │ └── UserSecretsConfigBuilder.cs └── packages │ ├── ConfigurationBuilders.Azure.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.Azure.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.Azure.nuspec │ └── tools │ │ └── Net471 │ │ ├── Install.ps1 │ │ └── Uninstall.ps1 │ ├── ConfigurationBuilders.AzureAppConfiguration.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration.nuspec │ └── tools │ │ └── Net471 │ │ ├── Install.ps1 │ │ └── Uninstall.ps1 │ ├── ConfigurationBuilders.Base.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.Base.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.Base.nuspec │ ├── content │ │ └── Net471 │ │ │ ├── config.install.xdt │ │ │ └── config.uninstall.xdt │ └── shared │ │ ├── content │ │ └── Net471 │ │ │ ├── config.install.xdt │ │ │ └── config.uninstall.xdt │ │ └── tools │ │ └── Net471 │ │ └── KeyValueConfigBuildersCommon.ps1 │ ├── ConfigurationBuilders.Environment.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.Environment.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.Environment.nuspec │ └── tools │ │ └── Net471 │ │ ├── Install.ps1 │ │ └── Uninstall.ps1 │ ├── ConfigurationBuilders.Json.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.Json.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.Json.nuspec │ └── tools │ │ └── Net471 │ │ ├── Install.ps1 │ │ └── Uninstall.ps1 │ ├── ConfigurationBuilders.KeyPerFile.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.KeyPerFile.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.KeyPerFile.nuspec │ └── tools │ │ └── Net471 │ │ ├── Install.ps1 │ │ └── Uninstall.ps1 │ ├── ConfigurationBuilders.UserSecrets.nupkg │ ├── Microsoft.Configuration.ConfigurationBuilders.UserSecrets.nuproj │ ├── Microsoft.Configuration.ConfigurationBuilders.UserSecrets.nuspec │ └── tools │ │ └── Net471 │ │ ├── Install.ps1 │ │ └── Uninstall.ps1 │ ├── assets │ ├── Readme-Azure.md │ ├── Readme-AzureAppConfig.md │ ├── Readme-Environment.md │ ├── Readme-Json.md │ ├── Readme-KeyPerFile.md │ ├── Readme-UserSecrets.md │ ├── Readme.md │ └── dotnet-icon.png │ └── packages.csproj ├── test.cmd ├── test └── Microsoft.Configuration.ConfigurationBuilders.Test │ ├── AzureAppConfigTests.cs │ ├── AzureTests.cs │ ├── BaseTests.cs │ ├── CommonBuilderTests.cs │ ├── ConnectionStringsSectionHandler2Tests.cs │ ├── EnvironmentTests.cs │ ├── KeyPerFileTests.cs │ ├── MultiThreadingTests.cs │ ├── OpenConfigTests.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── RecursionTests.cs │ ├── SimpleJsonTests.cs │ ├── Test.csproj │ ├── TestHelper.cs │ ├── UserSecretsTests.cs │ ├── UtilsTests.cs │ └── testConfigFiles │ ├── customAppSettings.config │ ├── empty.config │ ├── instance-appexe.config │ ├── instance-machine.config │ ├── recursion-appexe.config │ ├── recursion-machine.config │ ├── simpleJsonConflict.json │ ├── simpleJsonConnStrTest.json │ ├── simpleJsonOpenConfigTest.json │ └── simpleJsonTest.json └── tools ├── .verif.whitelist ├── MicrosoftConfigurationBuilders.settings.targets ├── NuGet.targets ├── NuGetProj.targets ├── signing.targets └── version.targets /.gitignore: -------------------------------------------------------------------------------- 1 | [Bb]in/ 2 | [Oo]bj/ 3 | src/**/[Bb]in/ 4 | src/**/[Oo]bj/ 5 | src/packages/**/signed/ 6 | src/packages/**/pp/ 7 | test/**/[Bb]in/ 8 | test/**/[Oo]bj/ 9 | .vs/ 10 | .binaries/ 11 | msbuild.* 12 | /packages/ 13 | samples/**/[Bb]in/ 14 | samples/**/[Oo]bj/ 15 | samples/**/[Pp]ublish[Pp]rofiles/ 16 | samples/**/[Ss]ervice[Dd]ependencies/ 17 | *.user 18 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/.nuget/NuGet.exe -------------------------------------------------------------------------------- /CODE-OF-CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | This project has adopted the code of conduct defined by the Contributor Covenant 4 | to clarify expected behavior in our community. 5 | 6 | For more information, see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct). 7 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | One of the easiest ways to contribute is to participate in discussions and discuss issues. You can also contribute by submitting pull requests with code changes. 4 | 5 | ## General feedback and discussions? 6 | Please start a discussion on the [ConfigurationBuilders repo issue tracker](https://github.com/aspnet/MicrosoftConfigurationBuilders/issues). 7 | 8 | ## Bugs and feature requests? 9 | For non-security related bugs please log a new issue on the [ConfigurationBuilders repo issue tracker](https://github.com/aspnet/MicrosoftConfigurationBuilders/issues). 10 | 11 | ## Reporting security issues and bugs 12 | Security issues and bugs should be reported privately, via email, to the Microsoft Security Response Center (MSRC) secure@microsoft.com. You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Further information, including the MSRC PGP key, can be found in the [Security TechCenter](https://technet.microsoft.com/en-us/security/ff852094.aspx). 13 | 14 | ## Filing issues 15 | When filing issues, please use our [bug filing templates](https://github.com/aspnet/MicrosoftConfigurationBuilders/wiki/Functional-bug-template). 16 | The best way to get your bug fixed is to be as detailed as you can be about the problem. 17 | Providing a minimal project with steps to reproduce the problem is ideal. 18 | Here are questions you can answer before you file a bug to make sure you're not missing any important information. 19 | 20 | 1. Did you read the [documentation](https://github.com/aspnet/MicrosoftConfigurationBuilders/wiki)? 21 | 2. Did you include the snippet of broken code in the issue? 22 | 3. What are the *EXACT* steps to reproduce this problem? 23 | 4. What version Powershell are you using? 24 | 5. What version of VS (including update version) are you using? 25 | 26 | GitHub supports [markdown](https://help.github.com/articles/github-flavored-markdown/), so when filing bugs make sure you check the formatting before clicking submit. 27 | 28 | ## Contributing code and content 29 | 30 | **Obtaining the source code** 31 | 32 | If you are an outside contributer, please fork the repository. See the GitHub documentation for [forking a repo](https://help.github.com/articles/fork-a-repo/) if you have any questions about this. 33 | 34 | **Building the source code** 35 | 36 | To build the project and run tests, you need to register the public key token for verification skip: 37 | 38 | 1. Open a Visual Studio developer prompt as administrator. 39 | 2. Run `sn -Vr *,31bf3856ad364e35 40 | 3. Run `build.cmd` to restore NuGet packages, build the solution, and run tests. 41 | 42 | **MSB3276 -or- Updating binding redirects in SampleWebApp** 43 | 44 | These projects are not SDK-style projects. The sample web application will not be able to load all the dependent assemblies for it's project references without a 45 | complete set of binding redirects, and you might see a 'MSB3276' warning in the build output. Visual Studio can generate this list automatically, but it has no affect 46 | when running the sample site because the bindings are placed in a *.dll.config file instead of web.config. 47 | 48 | To update the bindings in web.config, set the `UpdateBindingRedirectsAfterBuild` property in the 49 | [SampleWebApp.csproj](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/samples/SampleWebApp/SampleWebApp.csproj#L21) 50 | file to `'true'`, then rebuild the web site. You will still see the build warning when you first build because the bindings are not updated until after the build. 51 | Subsequent builds should no longer see the warning. This step only needs to be done once after updating any dependencies, so don't forget to unset the 52 | `UpdateBindingRedirectsAfterBuild` property when you're done. 53 | 54 | **Submitting a pull request** 55 | 56 | You will need to sign a [Contributor License Agreement](https://cla.opensource.microsoft.com//) when submitting your pull request. To complete the Contributor License Agreement (CLA), you will need to follow the instructions provided by the CLA bot when you send the pull request. This needs to only be done once for any Microsoft OSS project. 57 | 58 | If you don't know what a pull request is read this article: https://help.github.com/articles/using-pull-requests. Make sure the respository can build and all tests pass. 59 | 60 | **Commit/Pull Request Format** 61 | 62 | ``` 63 | Summary of the changes (Less than 80 chars) 64 | - Detail 1 65 | - Detail 2 66 | 67 | Addresses #bugnumber (in this specific format) 68 | ``` 69 | 70 | **Tests** 71 | 72 | - Tests need to be provided for every bug/feature that is completed. 73 | - Tests only need to be present for issues that need to be verified by QA (e.g. not tasks) 74 | - If there is a scenario that is far too hard to test there does not need to be a test for it. 75 | - "Too hard" is determined by the team as a whole. 76 | 77 | **Feedback** 78 | 79 | Your pull request will now go through extensive checks by the subject matter experts on our team. Please be patient; we have hundreds of pull requests across all of our repositories. Update your pull request according to feedback until it is approved by one of the ASP.NET team members. After that, one of our team members will add the pull request to **dev**. -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Microsoft Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MicrosoftConfigurationBuilders.msbuild: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | The .NET Core and ASP.NET Core support policy, including supported versions can be found at the [.NET Core Support Policy Page](https://dotnet.microsoft.com/platform/support/policy/dotnet-core). 6 | 7 | ## Reporting a Vulnerability 8 | 9 | Security issues and bugs should be reported privately to the Microsoft Security Response Center (MSRC), either by emailing secure@microsoft.com or via the portal at https://msrc.microsoft.com. 10 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your 11 | original message. Further information, including the MSRC PGP key, can be found in the [MSRC Report an Issue FAQ](https://www.microsoft.com/en-us/msrc/faqs-report-an-issue). 12 | 13 | Reports via MSRC may qualify for the .NET Core Bug Bounty. Details of the .NET Core Bug Bounty including terms and conditions are at [https://aka.ms/corebounty](https://aka.ms/corebounty). 14 | 15 | Please do not open issues for anything you think might have a security implication. 16 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | setlocal 4 | set EnableNuGetPackageRestore=true 5 | 6 | set MSBUILDEXE=msbuild.exe 7 | 8 | set cfgOption=/p:Configuration=Release 9 | REM set cfgOption=/p:Configuration=Debug 10 | REM set cfgOption=/p:Configuration=Debug;Release 11 | if not "%1"=="" set cfgOption=/p:Configuration= 12 | 13 | set logOptions=/v:n /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err 14 | REM set logOptions=/v:diag /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err 15 | 16 | %MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:BuildAll %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%* 17 | 18 | endlocal 19 | -------------------------------------------------------------------------------- /clean.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | setlocal 4 | 5 | set MSBUILDEXE=msbuild.exe 6 | 7 | set cfgOption=/p:Configuration=Release 8 | REM set cfgOption=/p:Configuration=Debug 9 | REM set cfgOption=/p:Configuration=Debug;Release 10 | if not "%1"=="" set cfgOption=/p:Configuration= 11 | 12 | set logOptions=/v:n /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err 13 | REM set logOptions=/v:diag /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err 14 | 15 | %MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:Clean %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%* 16 | del /F msbuild.log 17 | del /F msbuild.wrn 18 | del /F msbuild.err 19 | 20 | endlocal 21 | -------------------------------------------------------------------------------- /docs/CustomConfigBuilders.md: -------------------------------------------------------------------------------- 1 | # Implementing More Key/Value Config Builders 2 | 3 | If you don't see a config builder here that suits your needs, you can write your own. Referencing the `Basic` nuget package for this project will get you the base upon which all of these builders inherit. Most of the heavy-ish lifting and consistent behavior across key/value config builders comes from this base. Take a look at the code for more detail, but in many cases implementing a custom key/value config builder in this same vein is as easy as inheriting the base, and implementing two basic methods. 4 | ```CSharp 5 | using Microsoft.Configuration.ConfigurationBuilders; 6 | 7 | public class CustomConfigBuilder : KeyValueConfigBuilder 8 | { 9 | public override string GetValue(string key) 10 | { 11 | // Key lookup should be case-insensitive, because most key/value collections in .Net config sections are as well. 12 | return "Value for given key, or null."; 13 | } 14 | 15 | public override ICollection> GetAllValues(string prefix) 16 | { 17 | // Populate the return collection a little more smartly. ;) 18 | return new Dictionary() { { "one", "1" }, { "two", "2" } }; 19 | } 20 | } 21 | ``` 22 | 23 | Additionally, there are a few virtual methods that you can take advantage of for more advanced techniques. 24 | ```CSharp 25 | public class CustomConfigBuilder : KeyValueConfigBuilder 26 | { 27 | public override void Initialize(string name, NameValueCollection config) 28 | { 29 | // Use this initializer only for things that absolutely must be read from 30 | // the 'config' collection immediately upon creation. 31 | // AppSettings parameter substitution is not available at this point. 32 | // Use LazyInitialize(string, NameValueCollection) instead whenever possible. 33 | } 34 | 35 | protected override void LazyInitialize(string name, NameValueCollection config) 36 | { 37 | // Use this for things that don't need to be initialized until just before 38 | // config values are retrieved. 39 | // 40 | // *First, set the default values for 'Enabled' and 'CharacterMap' if 41 | // different from the base. 42 | // 43 | // *Second, be sure to call 'base.LazyInitialize(name, config)'. AppSettings 44 | // parameter substitution via 'UpdateConfigSettingWithAppSettings(parameterName)' 45 | // will be available after that call. 46 | // 47 | // *Third, check the value of 'Enabled' to see if there is any need to continue. 48 | // 49 | // *Lastly, read any additional parameters and do any other tasks needed 50 | // in preparation for retrieving config values. 51 | } 52 | 53 | public override bool MapKey(string key) 54 | { 55 | // If you know the format of the key pulled from *.config files is going to be invalid, but you 56 | // are able to translate the bad format to a known good format to get a value from your 57 | // config source, use this method. 58 | // Ex) AppSettings are commonly named things like "area:feature", but the ':' is not a legal 59 | // character for key names in Azure Key Vault. MapKey() can help translate the ':' to a 60 | // '-' in this case, which will allow the ability to look up a config value for this appSetting 61 | // in Key Vault, even though it's original key name is not valid in Key Vault. 62 | } 63 | 64 | public override bool ValidateKey(string key) 65 | { 66 | // A no-op by default. If your backing storage cannot handle certain characters, this is a one-stop 67 | // place for screening key names. It is particularly helpful in `Strict` and `Token` modes where 68 | // key names for lookup are taken from *.config files and could potentially contain invalid 69 | // characters that cause exceptions in the backing config store. 70 | } 71 | 72 | public override string UpdateKey(string rawKey) 73 | { 74 | // Just before replacing retrieved values in a config section, this method gets called. 75 | // 'AzureKeyVaultConfigBuilder' uses this override to strip version tags from keys. 76 | } 77 | } 78 | ``` 79 | -------------------------------------------------------------------------------- /samples/SampleConsoleApp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 |
7 |
8 |
9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | ${expandedSetting1} 57 | ${expandedSetting2} 58 | 59 | 60 | 61 | 62 | 63 | First test of applicationSettings. 64 | 65 | 66 | Will be replaced by Environment. 67 | 68 | 69 | Will be replaced by Environment. 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /samples/SampleConsoleApp/ClientSettings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace SampleConsoleApp { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.0.3.0")] 16 | internal sealed partial class ClientSettings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static ClientSettings defaultInstance = ((ClientSettings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new ClientSettings()))); 19 | 20 | public static ClientSettings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("First test of applicationSettings.")] 29 | public string FirstTestSetting { 30 | get { 31 | return ((string)(this["FirstTestSetting"])); 32 | } 33 | } 34 | 35 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 36 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 37 | [global::System.Configuration.DefaultSettingValueAttribute("Will be replaced by Environment.")] 38 | public string WINDIR { 39 | get { 40 | return ((string)(this["WINDIR"])); 41 | } 42 | } 43 | 44 | [global::System.Configuration.ApplicationScopedSettingAttribute()] 45 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 46 | [global::System.Configuration.DefaultSettingValueAttribute("Will be replaced by Environment.")] 47 | public string proCEssOR_archITECture { 48 | get { 49 | return ((string)(this["proCEssOR_archITECture"])); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /samples/SampleConsoleApp/ClientSettings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | First test of applicationSettings. 7 | 8 | 9 | Will be replaced by Environment. 10 | 11 | 12 | Will be replaced by Environment. 13 | 14 | 15 | -------------------------------------------------------------------------------- /samples/SampleConsoleApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Specialized; 3 | using System.Configuration; 4 | 5 | namespace SampleConsoleApp 6 | { 7 | internal class Program 8 | { 9 | static void Main(string[] args) 10 | { 11 | Console.WriteLine("---------- App Settings ----------"); 12 | foreach (string appsetting in ConfigurationManager.AppSettings.Keys) 13 | { 14 | Console.WriteLine($"{appsetting}\t{ConfigurationManager.AppSettings[appsetting]}"); 15 | } 16 | 17 | Console.WriteLine(""); 18 | Console.WriteLine(""); 19 | 20 | Console.WriteLine("---------- Connection Strings (Advanced Sample) ----------"); 21 | Console.WriteLine("Name ConnectionString ProviderName"); 22 | Console.WriteLine("------------------------+-------------------------------------------------+--------------------------------------------------"); 23 | foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings) 24 | { 25 | Console.WriteLine($"{cs.Name.PadRight(25)}{cs.ConnectionString.PadRight(50)}{cs.ProviderName}"); 26 | } 27 | 28 | Console.WriteLine(""); 29 | Console.WriteLine(""); 30 | 31 | Console.WriteLine("---------- Custom Settings ----------"); 32 | var customSettings = ConfigurationManager.GetSection("customSettings") as NameValueCollection; 33 | foreach (string setting in customSettings.Keys) 34 | { 35 | Console.WriteLine($"{setting}\t{customSettings[setting]}"); 36 | } 37 | 38 | Console.WriteLine(""); 39 | Console.WriteLine(""); 40 | 41 | Console.WriteLine("---------- Expanded Settings ----------"); 42 | var expandedSettings = ConfigurationManager.GetSection("expandedSettings") as NameValueCollection; 43 | foreach (string setting in expandedSettings.Keys) 44 | { 45 | Console.WriteLine($"{setting}\t{expandedSettings[setting]}"); 46 | } 47 | 48 | Console.WriteLine(""); 49 | Console.WriteLine(""); 50 | 51 | Console.WriteLine("---------- Client Application Settings ----------"); 52 | Console.WriteLine("Note: These _might_ be inaccurate due to the additional layers of building and caching that the"); 53 | Console.WriteLine("\tClient Application Settings framework uses. Read more about the Settings architecture"); 54 | Console.WriteLine("\there: https://docs.microsoft.com/en-us/dotnet/desktop/winforms/advanced/application-settings-architecture?view=netframeworkdesktop-4.8"); 55 | Console.WriteLine("-------------------------------------------------"); 56 | foreach (SettingsProperty sp in ClientSettings.Default.Properties) 57 | { 58 | Console.WriteLine($"{sp.Name}\t{ClientSettings.Default[sp.Name]}"); 59 | } 60 | Console.WriteLine("-------------------------------------------------"); 61 | Console.WriteLine("Note: It is also possible to skip the extra layers of the Client Application Settings framework."); 62 | Console.WriteLine("\tHowever, going this route loses the strongly and richly typed nature of Client Application"); 63 | Console.WriteLine("\tsettings. And at this point, its no different from using 'appSettings.' Code that goes through"); 64 | Console.WriteLine("\tthe full Client Settings stack will still see things as they look above, not below."); 65 | Console.WriteLine("-------------------------------------------------"); 66 | var css = ConfigurationManager.GetSection("applicationSettings/SampleConsoleApp.ClientSettings") as ClientSettingsSection; 67 | foreach (SettingElement setting in css.Settings) 68 | { 69 | Console.WriteLine($"{setting.Name}\t{setting.Value.ValueXml.InnerXml}"); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /samples/SampleConsoleApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SampleConsoleApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft IT")] 12 | [assembly: AssemblyProduct("SampleConsoleApp")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft IT 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0dbfa194-1632-40c0-a072-c59a9280412b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SampleConsoleApp/SampleConsoleApp.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {0DBFA194-1632-40C0-A072-C59A9280412B} 8 | Exe 9 | SampleConsoleApp 10 | SampleConsoleApp 11 | v4.7.1 12 | 512 13 | PackageReference 14 | true 15 | true 16 | true 17 | 18 | 19 | AnyCPU 20 | true 21 | full 22 | false 23 | bin\Debug\ 24 | DEBUG;TRACE 25 | prompt 26 | 4 27 | 28 | 29 | AnyCPU 30 | pdbonly 31 | true 32 | bin\Release\ 33 | TRACE 34 | prompt 35 | 4 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | True 53 | True 54 | ClientSettings.settings 55 | 56 | 57 | 58 | 59 | 60 | SettingsSingleFileGenerator 61 | ClientSettings.Designer.cs 62 | 63 | 64 | 65 | 66 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 67 | Base 68 | 69 | 70 | {c6530e81-d8d8-47a8-912e-d2939f801835} 71 | Environment 72 | 73 | 74 | {84e0ce5d-4af2-414f-a940-22b3f93fc727} 75 | Json 76 | 77 | 78 | {60c31149-44ed-4789-b5c3-aaa5d3b2fcf1} 79 | KeyPerFile 80 | 81 | 82 | {c60d6cbb-d513-4692-81a6-0be5d45e4702} 83 | UserSecrets 84 | 85 | 86 | {baa5eb76-5a85-48d6-9e8f-a01a309a2879} 87 | SamplesLib 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /samples/SampleItems/KeyPerFileRoot/KPF-Setting1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/samples/SampleItems/KeyPerFileRoot/KPF-Setting1 -------------------------------------------------------------------------------- /samples/SampleItems/KeyPerFileRoot/KPF-Setting2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/samples/SampleItems/KeyPerFileRoot/KPF-Setting2 -------------------------------------------------------------------------------- /samples/SampleItems/KeyPerFileRoot/SubFeatures/KPF-SubFeatureA: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/samples/SampleItems/KeyPerFileRoot/SubFeatures/KPF-SubFeatureA -------------------------------------------------------------------------------- /samples/SampleItems/KeyPerFileRoot/SubFeatures/KPF-SubFeatureB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/samples/SampleItems/KeyPerFileRoot/SubFeatures/KPF-SubFeatureB -------------------------------------------------------------------------------- /samples/SampleItems/KeyPerFileRoot/SubFeatures/ignore.KPF-SubFeatureC: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/samples/SampleItems/KeyPerFileRoot/SubFeatures/ignore.KPF-SubFeatureC -------------------------------------------------------------------------------- /samples/SampleItems/KeyPerFileRoot/ignore.KPF-Setting3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/samples/SampleItems/KeyPerFileRoot/ignore.KPF-Setting3 -------------------------------------------------------------------------------- /samples/SampleItems/secrets.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /samples/SampleWebApp/App_Data/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "jsonSetting1": "From Json Root", 3 | "jsonConnectionString1": "CS From Json Root", 4 | 5 | "appSettings": { 6 | "jsonSubSetting2": "From AppSettings Json object", 7 | "jsonSub": { 8 | "subSetting3": "From sub-property of AppSettings Json object" 9 | }, 10 | "jsonInteger": 42 11 | }, 12 | 13 | "connectionStrings": { 14 | "jsonConnectionString1": "CS1 From ConnectionStrings Json object", 15 | "specialFeature": { 16 | "connStr": "Special feature CS From ConnectionStrings Json object" 17 | }, 18 | "jsonAdvConnStr": { 19 | "connectionString": "Advanced ConnectionString", 20 | "providerName": "Advanced ProviderName" 21 | } 22 | }, 23 | 24 | "customSettings": { 25 | "jsonCustomSetting1": "Custom Setting from Json", 26 | "jsonConnectionString2": "CS2 From ConnectionStrings Json object", 27 | "jsonComplex": { 28 | "setting1": "Complex Setting 1", 29 | "setting2": "Complex Setting 2", 30 | "jsonArrayOfSettings": [ "one", "two", "three" ] 31 | } 32 | }, 33 | 34 | "expandedSettings": { 35 | "expandedSetting1": "", 36 | "expandedSetting2": "" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /samples/SampleWebApp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SampleWebApp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("SampleWebApp")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("590892dd-f842-4e7c-9400-4c6451c16b1a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /samples/SampleWebApp/default.aspx: -------------------------------------------------------------------------------- 1 | <% @Page Language="C#" %> 2 | <% @Import Namespace="System.Configuration" %> 3 | <% @Import Namespace="System.Web.Configuration" %> 4 | 5 | 32 | 33 | <% Response.Write("hello world! - " + DateTime.Now.ToString()); %> 34 | -------------------------------------------------------------------------------- /samples/SampleWebJob/Functions.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Configuration; 3 | using System.Text; 4 | using Microsoft.Azure.WebJobs; 5 | using Microsoft.Extensions.Logging; 6 | 7 | namespace SampleWebJob 8 | { 9 | public class Functions 10 | { 11 | // This function will get triggered/executed when a new message is written 12 | // on an Azure Queue called queue. 13 | public static void ProcessQueueMessage([QueueTrigger("queue")] string message, ILogger logger) 14 | { 15 | StringBuilder log = new StringBuilder(); 16 | 17 | log.AppendLine("==================================================================="); 18 | log.AppendLine("==================================================================="); 19 | log.AppendLine(message); 20 | 21 | log.AppendLine("---------- App Settings ----------"); 22 | foreach (string appsetting in ConfigurationManager.AppSettings.Keys) 23 | { 24 | log.AppendLine($"{appsetting}\t{ConfigurationManager.AppSettings[appsetting]}"); 25 | } 26 | 27 | log.AppendLine(""); 28 | log.AppendLine("---------- Connection Strings ----------"); 29 | foreach (ConnectionStringSettings cs in ConfigurationManager.ConnectionStrings) 30 | { 31 | log.AppendLine($"{cs.Name}\t{cs.ConnectionString}"); 32 | } 33 | 34 | log.AppendLine(""); 35 | log.AppendLine("---------- Environment ----------"); 36 | foreach (DictionaryEntry ev in System.Environment.GetEnvironmentVariables()) 37 | { 38 | log.AppendLine($"{ev.Key}\t{ev.Value}"); 39 | } 40 | 41 | logger.LogInformation(log.ToString()); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /samples/SampleWebJob/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Azure.WebJobs; 2 | using Microsoft.Extensions.Hosting; 3 | using Microsoft.Extensions.Logging; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.Threading.Tasks; 7 | 8 | namespace SampleWebJob 9 | { 10 | // To learn more about Microsoft Azure WebJobs SDK, please see https://go.microsoft.com/fwlink/?linkid=2250384 11 | internal class Program 12 | { 13 | // Please set AzureWebJobsStorage connection strings in appsettings.json for this WebJob to run. 14 | public static async Task Main(string[] args) 15 | { 16 | var builder = new HostBuilder() 17 | .UseEnvironment(EnvironmentName.Development) 18 | .ConfigureWebJobs(b => 19 | { 20 | b.AddAzureStorageCoreServices() 21 | .AddAzureStorageQueues(); 22 | }) 23 | .ConfigureLogging((context, b) => 24 | { 25 | b.SetMinimumLevel(LogLevel.Information); 26 | b.AddConsole(); 27 | }); 28 | 29 | 30 | var host = builder.Build(); 31 | using (host) 32 | { 33 | ILogger logger = host.Services.GetService(typeof(ILogger)) as ILogger; 34 | 35 | await host.StartAsync(); 36 | Functions.ProcessQueueMessage("Manual trigger of ProcessMessageQ", logger); 37 | await host.StopAsync(); 38 | } 39 | } 40 | } 41 | } 42 | 43 | 44 | -------------------------------------------------------------------------------- /samples/SampleWebJob/SampleWebJob.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | Exe 4 | net471 5 | true 6 | $(AssemblyName) 7 | Continuous 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | PreserveNewest 26 | 27 | 28 | Always 29 | 30 | 31 | -------------------------------------------------------------------------------- /samples/SampleWebJob/Settings.job: -------------------------------------------------------------------------------- 1 | { 2 | 3 | // Examples: 4 | 5 | // Runs every minute 6 | // "schedule": "0 * * * * *" 7 | 8 | // Runs every 15 minutes 9 | // "schedule": "0 */15 * * * *" 10 | 11 | // Runs every hour (i.e. whenever the count of minutes is 0) 12 | // "schedule": "0 0 * * * *" 13 | 14 | // Runs every hour from 9 AM to 5 PM 15 | // "schedule": "0 0 9-17 * * *" 16 | 17 | // Runs at 9:30 AM every day 18 | // "schedule": "0 30 9 * * *" 19 | 20 | // Runs at 9:30 AM every week day 21 | // "schedule": "0 30 9 * * 1-5" 22 | } -------------------------------------------------------------------------------- /samples/SampleWebJob/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /samples/SampleWebJob/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AzureWebJobsStorage": "UseDevelopmentStorage=true" 3 | } -------------------------------------------------------------------------------- /samples/SamplesLib/ClientSettingsSectionHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Linq; 5 | using System.Xml; 6 | using Microsoft.Configuration.ConfigurationBuilders; 7 | 8 | namespace SamplesLib 9 | { 10 | /// 11 | /// A class that can be used by s to apply key/value config pairs to . 12 | /// 13 | public class ClientSettingsSectionHandler : SectionHandler 14 | { 15 | private readonly XmlDocument _doc = new XmlDocument(); 16 | 17 | /// 18 | /// Updates an existing app setting in the assigned with a new key and a new value. The old setting 19 | /// can be located using the parameter. If an old setting is not found, a new setting should be inserted. 20 | /// 21 | /// The updated key name for the app setting. 22 | /// The updated value for the app setting. 23 | /// The old key name for the app setting, or null. 24 | /// The old key name for the app setting, or null., or null. 25 | public override void InsertOrUpdate(string newKey, string newValue, string oldKey = null, object oldItem = null) 26 | { 27 | if (newValue != null) 28 | { 29 | // Make sure there are no entries using the old or new name other than this one 30 | SettingElement oldSetting = oldItem as SettingElement; 31 | if (oldSetting != null) 32 | ConfigSection.Settings.Remove(oldSetting); 33 | SettingElement conflictSetting = ConfigSection.Settings.Get(newKey); 34 | if (conflictSetting != null) 35 | ConfigSection.Settings.Remove(conflictSetting); 36 | 37 | // Create the new setting, preserving serializeAs type if possible 38 | SettingElement setting = oldSetting ?? new SettingElement(); 39 | setting.Name = newKey; 40 | 41 | // Set the new value 42 | SettingValueElement v = new SettingValueElement(); 43 | v.ValueXml = _doc.CreateElement("value"); 44 | v.ValueXml.InnerXml = newValue; 45 | setting.Value = v; 46 | 47 | // Add the setting to the config section 48 | ConfigSection.Settings.Add(setting); 49 | } 50 | } 51 | 52 | /// 53 | /// Gets an for iterating over the key/value pairs contained in the assigned . /> 54 | /// 55 | /// An enumerator over tuples where the values of the tuple are the existing key for each setting, the old value for the 56 | /// setting, and the existing key for the setting again as the state which will be returned unmodified when updating. 57 | public override IEnumerable> KeysValuesAndState() 58 | { 59 | // Grab a copy of the settings collection since we are using 'yield' and the collection may change on us. 60 | SettingElement[] allSettings = new SettingElement[ConfigSection.Settings.Count]; 61 | ConfigSection.Settings.CopyTo(allSettings, 0); 62 | 63 | foreach (SettingElement setting in allSettings) 64 | yield return Tuple.Create(setting.Name, setting.Value?.ValueXml?.InnerXml, (object)setting); 65 | } 66 | 67 | /// 68 | /// Attempt to lookup the original key casing so it can be preserved during greedy updates which would otherwise lose 69 | /// the original casing in favor of the casing used in the config source. 70 | /// 71 | /// The key to find original casing for. 72 | /// A string containing the key with original casing from the config section, or the key as passed in if no match 73 | /// can be found. 74 | public override string TryGetOriginalCase(string requestedKey) 75 | { 76 | if (!String.IsNullOrWhiteSpace(requestedKey)) 77 | { 78 | var setting = ConfigSection.Settings.Get(requestedKey); 79 | if (setting != null) 80 | return setting.Name; 81 | } 82 | 83 | return base.TryGetOriginalCase(requestedKey); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /samples/SamplesLib/ExpandWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Configuration; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Xml; 8 | using Microsoft.Configuration.ConfigurationBuilders; 9 | 10 | namespace SamplesLib 11 | { 12 | public class ExpandWrapper : ConfigurationBuilder where T : KeyValueConfigBuilder, new() 13 | { 14 | private static MethodInfo _expandTokensMethod = typeof(KeyValueConfigBuilder).GetMethod("ExpandTokens", BindingFlags.NonPublic | BindingFlags.Instance); 15 | private T _underlyingBuilder; 16 | 17 | public ExpandWrapper() { _underlyingBuilder = new T(); } 18 | 19 | public override void Initialize(string name, NameValueCollection config) => _underlyingBuilder.Initialize(name, config); 20 | 21 | public override XmlNode ProcessRawXml(XmlNode rawXml) 22 | { 23 | rawXml = _underlyingBuilder.ProcessRawXml(rawXml); 24 | 25 | // !!!DO NOT APPLY TO APPSETTINGS!!! 26 | // AppSettings is special because it can be implicitly referenced when looking for config builder 27 | // settings, while it can simultaneously be processed by config builders. There used to be special 28 | // logic to help manage potential recursion in the base KeyValueConfigBuilder class, but that 29 | // protection is no more since 'Expand' mode and the use of _both_ ProcessRawXml() and ProcessConfigSection() 30 | // have been removed. 31 | if (rawXml.Name != "appSettings") // System.Configuration hard codes this, so we might as well too. 32 | { 33 | // Checking Enabled will kick off LazyInit, so only do that if we are actually going to do work here. 34 | if (_underlyingBuilder.Mode == KeyValueMode.Token && _underlyingBuilder.Enabled != KeyValueEnabled.Disabled) 35 | { 36 | // Old Expand-mode would do a recursion check here. We don't have internal access to RecursionGuard. 37 | return ExpandTokens(rawXml); 38 | } 39 | } 40 | 41 | return rawXml; 42 | } 43 | 44 | public override ConfigurationSection ProcessConfigurationSection(ConfigurationSection configSection) 45 | { 46 | // We have overridden the meaning of "Token" mode for this class. Don't do any processing in that mode. 47 | if (_underlyingBuilder.Mode == KeyValueMode.Token) 48 | return configSection; 49 | 50 | return _underlyingBuilder.ProcessConfigurationSection(configSection); 51 | } 52 | 53 | private XmlNode ExpandTokens(XmlNode rawXml) 54 | { 55 | string rawXmlString = rawXml.OuterXml; 56 | if (String.IsNullOrEmpty(rawXmlString)) 57 | return rawXml; 58 | 59 | string updatedXmlString = (string)_expandTokensMethod.Invoke(_underlyingBuilder, new object[] { rawXmlString }); 60 | 61 | XmlDocument doc = new XmlDocument(); 62 | doc.PreserveWhitespace = true; 63 | doc.LoadXml(updatedXmlString); 64 | return doc.DocumentElement; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /samples/SamplesLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SamplesLib")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft IT")] 12 | [assembly: AssemblyProduct("SamplesLib")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft IT 2022")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("b3f1c0ad-957b-4453-a830-f104fe368bc4")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /samples/SamplesLib/SamplesLib.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {BAA5EB76-5A85-48D6-9E8F-A01A309A2879} 8 | Library 9 | Properties 10 | SamplesLib 11 | SamplesLib 12 | v4.7.1 13 | 512 14 | true 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 52 | Base 53 | 54 | 55 | {84e0ce5d-4af2-414f-a940-22b3f93fc727} 56 | Json 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /src/35MSSharedLib1024.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/src/35MSSharedLib1024.snk -------------------------------------------------------------------------------- /src/Azure/Azure.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {345C5437-4990-45DC-BE34-6E37AA05D8D2} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.Azure 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | ..\obj\ 31 | 32 | 33 | portable 34 | true 35 | TRACE 36 | prompt 37 | 4 38 | ..\obj\ 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 51 | Base 52 | 53 | 54 | 55 | 56 | 1.11.4 57 | 58 | 59 | 4.4.0 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /src/Azure/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AzureKeyVaultConfigBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("AzureKeyVaultConfigBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("345c5437-4990-45dc-be34-6e37aa05d8d2")] 24 | -------------------------------------------------------------------------------- /src/AzureAppConfig/AzureAppConfig.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {3F1BB24A-355F-49E7-B396-6AA2EB5DDA0E} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | ..\obj\ 31 | 32 | 33 | portable 34 | true 35 | TRACE 36 | prompt 37 | 4 38 | ..\obj\ 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 51 | Base 52 | 53 | 54 | 55 | 56 | 1.3.0 57 | 58 | 59 | 1.11.4 60 | 61 | 62 | 4.4.0 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /src/AzureAppConfig/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("AzureAppConfiguration")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("AzureAppConfiguration")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2019")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("60c31149-44ed-4789-b5c3-aaa5d3b2fcf1")] 24 | -------------------------------------------------------------------------------- /src/Base/Base.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {F382FBF8-146D-4968-A199-90D37F9EF9A7} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.Base 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | true 23 | full 24 | false 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | ..\obj\ 29 | 30 | 31 | portable 32 | true 33 | TRACE 34 | prompt 35 | 4 36 | ..\obj\ 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /src/Base/KeyValueEnabled.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | namespace Microsoft.Configuration.ConfigurationBuilders 5 | { 6 | /// 7 | /// Possible modes (or behaviors) for key/value substitution. 8 | /// 9 | public enum KeyValueEnabled 10 | { 11 | /// 12 | /// Will execute KeyValueConfigurationBuilder and throw on error. 13 | /// 14 | Enabled, 15 | /// 16 | /// Will not execute KeyValueConfigurationBuilder. 17 | /// 18 | Disabled, 19 | /// 20 | /// Will execute KeyValueConfigurationBuilder but not report errors. 21 | /// 22 | Optional, 23 | 24 | // For convenience, allow true/false in the builder attribute as well. 25 | /// 26 | /// Same as Enabled. 27 | /// 28 | True = Enabled, 29 | /// 30 | /// Same as Disabled. 31 | /// 32 | False = Disabled 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Base/KeyValueExceptions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | using System; 5 | using System.Configuration; 6 | 7 | namespace Microsoft.Configuration.ConfigurationBuilders 8 | { 9 | internal class KeyValueExceptionHelper 10 | { 11 | public static Exception CreateKVCException(string msg, Exception ex, ConfigurationBuilder cb) 12 | { 13 | 14 | // If it's a ConfigurationErrorsException though, that means its coming from a re-entry to the 15 | // config system. That's where the root issue is, and that's the "Error Message" we want on 16 | // the top of the exception chain. So wrap it in another ConfigurationErrorsException of 17 | // sorts so the config system will use it instead of rolling it's own at this secondary 18 | // level. 19 | if (ex is ConfigurationErrorsException ceex) 20 | { 21 | var inner = new KeyValueConfigBuilderException($"'{cb.Name}' {msg} ==> {ceex.InnerException?.Message ?? ceex.Message}", ex.InnerException); 22 | return new KeyValueConfigurationErrorsException(ceex.Message, inner); 23 | } 24 | 25 | var ff = new KeyValueConfigBuilderException(); 26 | return new KeyValueConfigBuilderException($"'{cb.Name}' {msg}: {ex.Message}", ex); 27 | } 28 | 29 | // We only want to wrap the original exception. Once we wrap it, just keep raising the wrapped 30 | // exception so we don't create an endless chain of exception wrappings that are not helpful when 31 | // being surfaced in a YSOD or similar. Use this helper to determine if wrapping is needed. 32 | public static bool IsKeyValueConfigException(Exception ex) => (ex is KeyValueConfigBuilderException) || (ex is KeyValueConfigurationErrorsException); 33 | } 34 | 35 | // There are two different exception types here because the .Net config system treats 36 | // ConfigurationErrorsExceptions differently. It considers it to be a pre-wrapped and ready for 37 | // presentation exception. Other exceptions get wrapped by the config system. We don't want 38 | // to lose that "pre-wrapped-ness" if the exception has already been through .Net config. 39 | 40 | /// 41 | /// An exception that wraps the root failure due to non-config exceptions while processing Key Value Config Builders. 42 | /// 43 | [Serializable] 44 | public class KeyValueConfigBuilderException : Exception 45 | { 46 | /// 47 | /// Initializes a new instance of the class. 48 | /// 49 | public KeyValueConfigBuilderException() : base() { } 50 | 51 | internal KeyValueConfigBuilderException(string msg, Exception inner) : base(msg, inner) { } 52 | } 53 | 54 | /// 55 | /// An exception that wraps the root failure due to config exceptions while processing Key Value Config Builders. 56 | /// 57 | [Serializable] 58 | public class KeyValueConfigurationErrorsException : ConfigurationErrorsException 59 | { 60 | /// 61 | /// Initializes a new instance of the class. 62 | /// 63 | public KeyValueConfigurationErrorsException() : base() { } 64 | 65 | internal KeyValueConfigurationErrorsException(string msg, Exception inner) : base(msg, inner) { } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Base/KeyValueMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | namespace Microsoft.Configuration.ConfigurationBuilders 5 | { 6 | /// 7 | /// Possible modes (or behaviors) for key/value substitution. 8 | /// 9 | public enum KeyValueMode 10 | { 11 | /// 12 | /// Replaces 'value' if 'key' is matched. Only operates on known key/value config sections. 13 | /// 14 | Strict, 15 | /// 16 | /// Inserts all 'values' regardless of the previous existence of the 'key.' Only operates on known key/value config sections. 17 | /// 18 | Greedy, 19 | /// 20 | /// Replace 'key'-specifying tokens in the 'key' or 'value' parts of a config entry. 21 | /// 22 | Token = 3 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Base/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("KeyValueConfigBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("KeyValueConfigBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f382fbf8-146d-4968-a199-90d37f9ef9a7")] 24 | -------------------------------------------------------------------------------- /src/Base/RecursionGuard.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Configuration; 7 | using System.Threading; 8 | 9 | namespace Microsoft.Configuration.ConfigurationBuilders 10 | { 11 | /// 12 | /// Possible behaviors when dealing with config builder recursion. 13 | /// 14 | public enum RecursionGuardValues 15 | { 16 | /// 17 | /// [Default] Throw when reprocessing the same section. 18 | /// 19 | Throw, 20 | /// 21 | /// [!!May yield unexpected results in recursive conditions!!] Stop recursing, return without processing. 22 | /// 23 | Stop, 24 | /// 25 | /// [!!May result in deadlocks or stack overflow in recursive conditions!!] Do nothing. Continue recursing. 26 | /// 27 | Allow 28 | } 29 | 30 | /// 31 | /// Disposable object to help detect and handle problems with recursion. 32 | /// 33 | internal class RecursionGuard : IDisposable 34 | { 35 | private static readonly AsyncLocal> sectionsEntered = new AsyncLocal>(); 36 | 37 | internal bool ShouldStop = false; 38 | private readonly string sectionName; 39 | private readonly string builderName; 40 | 41 | internal RecursionGuard(ConfigurationBuilder configBuilder, string sectionName, RecursionGuardValues behavior) 42 | { 43 | // If behavior says "do nothing"... then let's do nothing. 44 | if (behavior == RecursionGuardValues.Allow) 45 | return; 46 | 47 | sectionsEntered.Value = sectionsEntered.Value ?? new Stack<(string, string)>(); 48 | builderName = $"{configBuilder.Name}[{configBuilder.GetType()}]"; 49 | 50 | // The idea here is that in this "thread" of execution, a config section is logged on this stack 51 | // while being processed by a builder. Ie, in ProcessRawXml() or ProcessConfigurationSection(). 52 | // Once the builder is done in each phase, it pops the section off the stack. [And the next builder 53 | // might pop it back on to do it's work.] The goal is to prevent an endless loop between sections 54 | // in one thread, not to prevent concurrent processing by multiple threads. 55 | // If we ever re-enter the same config section recursively, it will already be on the stack. 56 | // Since we push/pop for each builder, it does not cause problems with multiple builders in one chain. 57 | // Also, we can still enter a chain of different config sections so long as we don't re-enter any. 58 | // Unfortunately, we can't rely on much more than a simple section name since more information is 59 | // not available to us, especially in ProcessRawXml(). Fortunately, config sections are generally 60 | // top-level enough that there shouldn't really be any collisions here. 61 | var prev = FindSection(sectionsEntered.Value, sectionName); 62 | if (prev != null) 63 | { 64 | // Should we throw an exception? 65 | if (behavior == RecursionGuardValues.Throw) 66 | { 67 | // Don't touch sectionsEntered. We did not add to it. We should not take from it or 68 | // throw it away in case somebody wants to handle this exception. 69 | throw new InvalidOperationException($"The ConfigurationBuilder '{prev.Value.builder}' has recursively re-entered processing of the '{sectionName}' section."); 70 | } 71 | 72 | // If we don't throw, should we at least stop going down the rabbit hole? 73 | ShouldStop = (behavior == RecursionGuardValues.Stop); 74 | } 75 | 76 | // If we get here, then we will allow the section to be processed. Or at least we are returning 77 | // a guard instance and letting the caller decide what to do. We will be popping when we dispose, 78 | // so regardless of what our caller does, we should add the section name to the list of entered 79 | // sections, and also remember it so we know to remove it from the list when we are disposed. 80 | this.sectionName = sectionName; 81 | sectionsEntered.Value.Push((sectionName, builderName)); 82 | } 83 | 84 | public void Dispose() 85 | { 86 | // If we tracked the entering of a section... stop tracking now. 87 | if (sectionName != null) 88 | { 89 | var (section, builder) = sectionsEntered.Value.Pop(); 90 | 91 | // Sanity check to make sure we are un-tracking what we expect to un-track. 92 | if ((section != sectionName) || (builder != builderName)) { 93 | throw new InvalidOperationException($"The ConfigurationBuilder {builderName} has detected a mix up while processing of the '{sectionName}' section. ({builder},{section})"); 94 | } 95 | } 96 | } 97 | 98 | private static (string section, string builder)? FindSection(Stack<(string s, string b)> stack, string section) 99 | { 100 | foreach (var record in stack) 101 | if (record.s == section) 102 | return record; 103 | 104 | return null; 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /src/Base/SectionHandlerSection.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections.Specialized; 6 | using System.Configuration; 7 | using System.Reflection; 8 | 9 | namespace Microsoft.Configuration.ConfigurationBuilders 10 | { 11 | /// 12 | /// Provides programmatic access to the 'sectionHandlers' config section. This class can't be inherited. 13 | /// 14 | public sealed class SectionHandlersSection : ConfigurationSection 15 | { 16 | private static readonly string handlerSectionName = "Microsoft.Configuration.ConfigurationBuilders.SectionHandlers"; 17 | 18 | /// 19 | /// Gets the collection of s defined for processing config sections with s./> 20 | /// 21 | [ConfigurationProperty("handlers", IsDefaultCollection = true, Options = ConfigurationPropertyOptions.IsDefaultCollection)] 22 | public ProviderSettingsCollection Handlers 23 | { 24 | get { return (ProviderSettingsCollection)base["handlers"]; } 25 | } 26 | 27 | /// 28 | /// Used to initialize a default set of section handlers. (For the appSettings and connectionStrings sections.) 29 | /// 30 | protected override void InitializeDefault() 31 | { 32 | // This only runs once at the top "parent" level of the config stack. If there is already an 33 | // existing parent in the stack to inherit, then this does not get called. 34 | base.InitializeDefault(); 35 | if (Handlers != null) 36 | { 37 | Handlers.Add(new ProviderSettings("DefaultAppSettingsHandler", "Microsoft.Configuration.ConfigurationBuilders.AppSettingsSectionHandler")); 38 | Handlers.Add(new ProviderSettings("DefaultConnectionStringsHandler", "Microsoft.Configuration.ConfigurationBuilders.ConnectionStringsSectionHandler")); 39 | } 40 | } 41 | 42 | internal static ISectionHandler GetSectionHandler(T configSection) where T : ConfigurationSection 43 | { 44 | if (configSection == null) 45 | return null; 46 | 47 | SectionHandlersSection handlerSection = GetSectionHandlersSection(configSection); 48 | 49 | if (handlerSection != null) 50 | { 51 | // Look at each handler to see if it works on this section. Reverse order so last match wins. 52 | // .IsSubclassOf() requires an exact type match. So SectionHandler won't work. 53 | Type sectionHandlerGenericTemplate = typeof(SectionHandler<>); 54 | Type sectionHandlerDesiredType = sectionHandlerGenericTemplate.MakeGenericType(configSection.GetType()); 55 | for (int i = handlerSection.Handlers.Count; i-- > 0;) 56 | { 57 | Type handlerType = Type.GetType(handlerSection.Handlers[i].Type); 58 | if (handlerType != null && handlerType.IsSubclassOf(sectionHandlerDesiredType)) 59 | { 60 | if (Activator.CreateInstance(handlerType) is ISectionHandler handler) 61 | { 62 | ProviderSettings settings = handlerSection.Handlers[i]; 63 | NameValueCollection clonedParams = new NameValueCollection(settings.Parameters.Count); 64 | foreach (string key in settings.Parameters) 65 | clonedParams[key] = settings.Parameters[key]; 66 | 67 | MethodInfo init = sectionHandlerDesiredType.GetMethod("Initialize", BindingFlags.NonPublic | BindingFlags.Instance); 68 | init.Invoke(handler, new object[] { settings.Name, configSection, clonedParams }); 69 | 70 | return handler; 71 | } 72 | } 73 | } 74 | } 75 | 76 | throw new Exception($"Error in Configuration: Cannot find ISectionHandler for '{configSection.SectionInformation.Name}' section."); 77 | } 78 | 79 | private static SectionHandlersSection GetSectionHandlersSection(ConfigurationSection currentSection) 80 | { 81 | SectionHandlersSection handlersSection = (currentSection?.CurrentConfiguration?.GetSection(handlerSectionName) as SectionHandlersSection) 82 | ?? (ConfigurationManager.GetSection(handlerSectionName) as SectionHandlersSection); 83 | 84 | if (handlersSection == null) 85 | { 86 | handlersSection = new SectionHandlersSection(); 87 | handlersSection.InitializeDefault(); 88 | } 89 | 90 | return handlersSection; 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/Base/Utils.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | using System; 5 | using System.Configuration; 6 | using System.IO; 7 | using System.Reflection; 8 | 9 | namespace Microsoft.Configuration.ConfigurationBuilders 10 | { 11 | /// 12 | /// Utility methods commonly used by KeyValueConfigBuilders. 13 | /// 14 | public class Utils 15 | { 16 | private static bool? s_isAspNet = null; 17 | private static Type s_hostingEnvironmentType = null; 18 | 19 | /// 20 | /// Returns the physical file path that corresponds to the specified relative path. 21 | /// 22 | /// 23 | /// 24 | /// 25 | public static string MapPath(string path, ConfigurationSection configSection = null) 26 | { 27 | if (String.IsNullOrWhiteSpace(path)) 28 | return path; 29 | 30 | // Use 'as is' if the path is rooted. 31 | if (Path.IsPathRooted(path)) 32 | return path; 33 | 34 | // First try Server.MapPath in ASP.Net 35 | if (IsAspNet) 36 | { 37 | try 38 | { 39 | return ServerMapPath(path); 40 | } 41 | catch (Exception) { } 42 | } 43 | 44 | // Special case a '~' at the start should always use AppDomain.BaseDirectory 45 | if (path.StartsWith(@"~/") || path.StartsWith(@"~\")) 46 | path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path.Substring(2)); 47 | 48 | // Otherwise, non "rooted" paths should try to be relative to the config file if possible 49 | string configFile = configSection?.ElementInformation?.Source; 50 | string root = (configFile != null) ? Path.GetDirectoryName(configFile) : AppDomain.CurrentDomain.BaseDirectory; 51 | return Path.GetFullPath(Path.Combine(root, path)); 52 | } 53 | 54 | private static bool IsAspNet 55 | { 56 | get 57 | { 58 | if (s_isAspNet != null) 59 | return (bool)s_isAspNet; 60 | 61 | // Is System.Web already loaded? If not, we're not in Asp.Net. 62 | Assembly systemWeb = null; 63 | foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) 64 | { 65 | if (a.FullName.StartsWith("System.Web,")) 66 | { 67 | systemWeb = a; 68 | break; 69 | } 70 | } 71 | if (systemWeb == null) 72 | { 73 | s_isAspNet = false; 74 | return (bool)s_isAspNet; 75 | } 76 | 77 | // Get HostingEnvironment 78 | s_hostingEnvironmentType = systemWeb.GetType("System.Web.Hosting.HostingEnvironment"); 79 | if (s_hostingEnvironmentType == null) 80 | { 81 | s_isAspNet = false; 82 | return (bool)s_isAspNet; 83 | } 84 | 85 | // Check HostingEnvironment.IsHosted 86 | PropertyInfo isHosted = s_hostingEnvironmentType.GetProperty("IsHosted", BindingFlags.Public | BindingFlags.Static); 87 | if ((isHosted == null) || !(bool)isHosted.GetValue(null)) 88 | { 89 | s_hostingEnvironmentType = null; 90 | s_isAspNet = false; 91 | return (bool)s_isAspNet; 92 | } 93 | 94 | // If we got here, System.Web is loaded, and HostingEnvironment.IsHosted is true. Yay Asp.Net! 95 | s_isAspNet = true; 96 | return (bool)s_isAspNet; 97 | } 98 | } 99 | 100 | private static string ServerMapPath(string path) 101 | { 102 | if (s_hostingEnvironmentType == null) 103 | return path; 104 | 105 | MethodInfo mapPath = s_hostingEnvironmentType.GetMethod("MapPath", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(string) }, null); 106 | if (mapPath == null) 107 | return path; 108 | 109 | return (string)mapPath.Invoke(null, new object[] { path }); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Environment/Environment.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {C6530E81-D8D8-47A8-912E-D2939F801835} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.Environment 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | true 23 | full 24 | false 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | ..\obj\ 29 | 30 | 31 | portable 32 | true 33 | TRACE 34 | prompt 35 | 4 36 | ..\obj\ 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 49 | Base 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/Environment/EnvironmentConfigBuilder.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Collections.Specialized; 8 | 9 | namespace Microsoft.Configuration.ConfigurationBuilders 10 | { 11 | /// 12 | /// A ConfigurationProvider that retrieves values from environment variables. 13 | /// 14 | public class EnvironmentConfigBuilder : KeyValueConfigBuilder 15 | { 16 | /// 17 | /// Initializes the configuration builder lazily. 18 | /// 19 | /// The friendly name of the provider. 20 | /// A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider. 21 | protected override void LazyInitialize(string name, NameValueCollection config) 22 | { 23 | // Colons are common in appSettings keys, but not allowed in some environments. A common replacement 24 | // for them is the double underscore. Following .Net Core's example here. 25 | CharacterMap.Add(":", "__"); 26 | 27 | base.LazyInitialize(name, config); 28 | 29 | // At this point, we have our 'Enabled' choice. If we are disabled, we can stop right here. 30 | //Don't forget to add this here if we ever do anything beyond base.LazyInitialize() here. 31 | //if (Enabled == KeyValueEnabled.Disabled) return; 32 | } 33 | 34 | /// 35 | /// Looks up a single 'value' for the given 'key.' 36 | /// 37 | /// The 'key' to look up in the environment. (Prefix handling is not needed here.) 38 | /// The value corresponding to the given 'key' or null if no value is found. 39 | public override string GetValue(string key) 40 | { 41 | try 42 | { 43 | return Environment.GetEnvironmentVariable(key); 44 | } 45 | catch (Exception) 46 | { 47 | if (!IsOptional) 48 | throw; 49 | } 50 | 51 | return null; 52 | } 53 | 54 | /// 55 | /// Retrieves all known key/value pairs from the environment where the key begins with with . 56 | /// 57 | /// A prefix string to filter the list of potential keys retrieved from the source. 58 | /// A collection of key/value pairs. 59 | public override ICollection> GetAllValues(string prefix) 60 | { 61 | Dictionary values = new Dictionary(); 62 | 63 | try 64 | { 65 | foreach (DictionaryEntry de in Environment.GetEnvironmentVariables()) 66 | { 67 | // This won't ever throw for duplicate entries since underlying environment is case-insensitive. 68 | if (de.Key.ToString()?.StartsWith(prefix, StringComparison.OrdinalIgnoreCase) == true) 69 | values.Add(de.Key.ToString(), de.Value.ToString()); 70 | } 71 | } 72 | catch (Exception) 73 | { 74 | if (!IsOptional) 75 | throw; 76 | } 77 | 78 | return values; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Environment/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EnvironmentConfigBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("EnvironmentConfigBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f382fbf8-146d-4968-a199-90d37f9ef9a7")] 24 | -------------------------------------------------------------------------------- /src/Json/Json.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {84E0CE5D-4AF2-414F-A940-22B3F93FC727} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.Json 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | true 23 | full 24 | false 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | ..\obj\ 29 | 30 | 31 | portable 32 | true 33 | TRACE 34 | prompt 35 | 4 36 | ..\obj\ 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 51 | Base 52 | 53 | 54 | 55 | 56 | 4.7.1 57 | 58 | 59 | 60 | 4.7.2 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/Json/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("SimpleJsonConfigBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("SimpleJsonConfigBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("84e0ce5d-4af2-414f-a940-22b3f93fc727")] 24 | -------------------------------------------------------------------------------- /src/Json/SimpleJsonConfigBuilderMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. All rights reserved. 2 | // Licensed under the MIT license. See the License.txt file in the project root for full license information. 3 | 4 | namespace Microsoft.Configuration.ConfigurationBuilders 5 | { 6 | /// 7 | /// Possible modes (or paradigms) for parsing a json source file. 8 | /// 9 | public enum SimpleJsonConfigBuilderMode 10 | { 11 | /// 12 | /// The whole file is flattened into a single key/value collection. 13 | /// 14 | Flat, 15 | /// 16 | /// Use top-level objects to separate into different dictionaries per config section. 17 | /// 18 | Sectional 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/KeyPerFile/KeyPerFile.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {60C31149-44ED-4789-B5C3-AAA5D3B2FCF1} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.KeyPerFile 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | true 23 | full 24 | false 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | ..\obj\ 29 | 30 | 31 | portable 32 | true 33 | TRACE 34 | prompt 35 | 4 36 | ..\obj\ 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 49 | Base 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /src/KeyPerFile/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("KeyPerFileConfigBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("KeyPerFileConfigBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("60c31149-44ed-4789-b5c3-aaa5d3b2fcf1")] 24 | -------------------------------------------------------------------------------- /src/UserSecrets/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UserSecretsConfigBuilder")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("UserSecretsConfigBuilder")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f382fbf8-146d-4968-a199-90d37f9ef9a7")] 24 | -------------------------------------------------------------------------------- /src/UserSecrets/UserSecrets.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {C60D6CBB-D513-4692-81A6-0BE5D45E4702} 9 | Library 10 | Properties 11 | Microsoft.Configuration.ConfigurationBuilders 12 | Microsoft.Configuration.ConfigurationBuilders.UserSecrets 13 | $(OutputPath)$(AssemblyName).xml 14 | v4.7.1 15 | 512 16 | 17 | true 18 | true 19 | ..\35MSSharedLib1024.snk 20 | 21 | 22 | true 23 | full 24 | false 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | ..\obj\ 29 | 30 | 31 | portable 32 | true 33 | TRACE 34 | prompt 35 | 4 36 | ..\obj\ 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | {f382fbf8-146d-4968-a199-90d37f9ef9a7} 51 | Base 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Azure.nupkg/Microsoft.Configuration.ConfigurationBuilders.Azure.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.AzureKeyVaultConfigBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | tools\Net471\ 39 | 40 | 41 | tools\Net471\ 42 | 43 | 44 | docs\Readme.md 45 | 46 | 47 | images\dotnet-icon.png 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Azure.nupkg/Microsoft.Configuration.ConfigurationBuilders.Azure.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - Azure Builders 10 | A set of Configuration Builders for the .Net Framework that draw from Azure resources. 11 | A set of Configuration Builders for the .Net Framework that draw from Azure resources. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders Azure 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Azure.nupkg/tools/Net471/Install.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | ##### Describe the AzureKeyVault config builder ##### 9 | $keyVaultConfigBuilder = [BuilderDescription]@{ 10 | TypeName="$typeName$"; 11 | Assembly="$assemblyName$"; 12 | Version="$assemblyVersion$"; 13 | DefaultName="AzureKeyVault"; 14 | AllowedParameters=@( $keyValueCommonParameters + 15 | [ParameterDescription]@{ Name="vaultName"; IsRequired=$false; DefaultValue="[VaultName]" }, 16 | [ParameterDescription]@{ Name="uri"; IsRequired=$false }, 17 | [ParameterDescription]@{ Name="connectionString"; IsRequired=$false }, # Obsolete, but don't complain about it here. Still preserve it so people can revert back to the version that allows this. 18 | [ParameterDescription]@{ Name="version"; IsRequired=$false }, 19 | [ParameterDescription]@{ Name="preloadSecretNames"; IsRequired=$false }); 20 | } 21 | 22 | CommonInstall $keyVaultConfigBuilder 23 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Azure.nupkg/tools/Net471/Uninstall.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | CommonUninstall "$typeName$, $assemblyName$" 9 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.AzureAppConfiguration.nupkg/Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | tools\Net471\ 39 | 40 | 41 | tools\Net471\ 42 | 43 | 44 | docs\Readme.md 45 | 46 | 47 | images\dotnet-icon.png 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.AzureAppConfiguration.nupkg/Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - AzureAppConfiguration Builder 10 | A set of Configuration Builders for the .Net Framework that draw from Azure AppConfiguration stores. 11 | A set of Configuration Builders for the .Net Framework that draw from Azure AppConfiguration stores. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders AzureAppConfiguration 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.AzureAppConfiguration.nupkg/tools/Net471/Install.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | ##### Describe the AzureAppConfig config builder ##### 9 | $keyVaultConfigBuilder = [BuilderDescription]@{ 10 | TypeName="$typeName$"; 11 | Assembly="$assemblyName$"; 12 | Version="$assemblyVersion$"; 13 | DefaultName="AzureAppConfig"; 14 | AllowedParameters=@( $keyValueCommonParameters + 15 | [ParameterDescription]@{ Name="endpoint"; IsRequired=$false; DefaultValue="[Config_Store_Endpoint_Url]" }, 16 | [ParameterDescription]@{ Name="connectionString"; IsRequired=$false }, 17 | [ParameterDescription]@{ Name="keyFilter"; IsRequired=$false }, 18 | [ParameterDescription]@{ Name="labelFilter"; IsRequired=$false }, 19 | [ParameterDescription]@{ Name="acceptDateTime"; IsRequired=$false }; 20 | ) 21 | } 22 | 23 | CommonInstall $keyVaultConfigBuilder 24 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.AzureAppConfiguration.nupkg/tools/Net471/Uninstall.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | CommonUninstall "$typeName$, $assemblyName$" 9 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Base.nupkg/Microsoft.Configuration.ConfigurationBuilders.Base.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.KeyValueConfigBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | docs\Readme.md 39 | 40 | 41 | images\dotnet-icon.png 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Base.nupkg/Microsoft.Configuration.ConfigurationBuilders.Base.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - Base 10 | In .Net 4.7.1, the configuration system allows applications to use ConfigurationBuilders to build up and modify configuration at runtime when it is loaded. This package provides a base framework to ease development of basic key/value configuration builders. 11 | A base framework for basic key/value Configuration Builders for the .Net Framework. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Base.nupkg/content/Net471/config.install.xdt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Base.nupkg/content/Net471/config.uninstall.xdt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Base.nupkg/shared/content/Net471/config.install.xdt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Base.nupkg/shared/content/Net471/config.uninstall.xdt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Environment.nupkg/Microsoft.Configuration.ConfigurationBuilders.Environment.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | tools\Net471\ 39 | 40 | 41 | tools\Net471\ 42 | 43 | 44 | docs\Readme.md 45 | 46 | 47 | images\dotnet-icon.png 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Environment.nupkg/Microsoft.Configuration.ConfigurationBuilders.Environment.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - Environment 10 | A basic key/value Configuration Builder for the .Net Framework that draws from environment variables. 11 | A basic key/value Configuration Builder for the .Net Framework that draws from environment variables. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders Environment 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Environment.nupkg/tools/Net471/Install.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | ##### Describe the Environment config builder ##### 9 | $environmentConfigBuilder = [BuilderDescription]@{ 10 | TypeName="$typeName$"; 11 | Assembly="$assemblyName$"; 12 | Version="$assemblyVersion$"; 13 | DefaultName="Environment"; 14 | AllowedParameters=$keyValueCommonParameters; 15 | } 16 | 17 | CommonInstall $environmentConfigBuilder 18 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Environment.nupkg/tools/Net471/Uninstall.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | CommonUninstall "$typeName$, $assemblyName$" 9 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Json.nupkg/Microsoft.Configuration.ConfigurationBuilders.Json.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.SimpleJsonConfigBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | tools\Net471\ 39 | 40 | 41 | tools\Net471\ 42 | 43 | 44 | docs\Readme.md 45 | 46 | 47 | images\dotnet-icon.png 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Json.nupkg/Microsoft.Configuration.ConfigurationBuilders.Json.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - Json Builders 10 | A basic key/value Configuration Builder for the .Net Framework that draws from a json file. 11 | A basic key/value Configuration Builder for the .Net Framework that draws from a json file. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders Json 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Json.nupkg/tools/Net471/Install.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | ##### Describe the SimpleJson config builder ##### 9 | $jsonConfigBuilder = [BuilderDescription]@{ 10 | TypeName="$typeName$"; 11 | Assembly="$assemblyName$"; 12 | Version="$assemblyVersion$"; 13 | DefaultName="SimpleJson"; 14 | AllowedParameters=@( $keyValueCommonParameters + 15 | [ParameterDescription]@{ Name="jsonFile"; IsRequired=$true; DefaultValue="~/App_Data/settings.json" }, 16 | [ParameterDescription]@{ Name="jsonMode"; IsRequired=$false }); 17 | } 18 | 19 | CommonInstall $jsonConfigBuilder 20 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.Json.nupkg/tools/Net471/Uninstall.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | CommonUninstall "$typeName$, $assemblyName$" 9 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.KeyPerFile.nupkg/Microsoft.Configuration.ConfigurationBuilders.KeyPerFile.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.KeyPerFileConfigBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | tools\Net471\ 39 | 40 | 41 | tools\Net471\ 42 | 43 | 44 | docs\Readme.md 45 | 46 | 47 | images\dotnet-icon.png 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.KeyPerFile.nupkg/Microsoft.Configuration.ConfigurationBuilders.KeyPerFile.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - KeyPerFile 10 | A basic key/value Configuration Builder for the .Net Framework that draws single values from plain text files using the filename as the key. 11 | A basic key/value Configuration Builder for the .Net Framework that draws single values from plain text files using the filename as the key. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders KeyPerFile 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.KeyPerFile.nupkg/tools/Net471/Install.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | ##### Describe the KeyPerFile config builder ##### 9 | $keyPerFileConfigBuilder = [BuilderDescription]@{ 10 | TypeName="$typeName$"; 11 | Assembly="$assemblyName$"; 12 | Version="$assemblyVersion$"; 13 | DefaultName="KeyPerFile"; 14 | AllowedParameters=@( $keyValueCommonParameters + 15 | [ParameterDescription]@{ Name="directoryPath"; IsRequired=$true; DefaultValue="[PathToSourceDirectory]" }, 16 | [ParameterDescription]@{ Name="keyDelimiter"; IsRequired=$false }, 17 | [ParameterDescription]@{ Name="ignorePrefix"; IsRequired=$false }); 18 | } 19 | 20 | CommonInstall $keyPerFileConfigBuilder 21 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.KeyPerFile.nupkg/tools/Net471/Uninstall.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | CommonUninstall "$typeName$, $assemblyName$" 9 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.UserSecrets.nupkg/Microsoft.Configuration.ConfigurationBuilders.UserSecrets.nuproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder 6 | $(MSBuildProjectName) 7 | $(MSBuildProjectName) 8 | $(MSBuildProjectName).nuspec 9 | true 10 | 11 | 12 | 13 | $(AssemblyPath) 14 | lib\Net471 15 | 16 | 17 | $(OutputPath) 18 | lib\Net471 19 | 20 | 21 | $(OutputPath) 22 | lib\Net471 23 | 24 | 25 | 26 | content\Net471\app.config.install.xdt 27 | 28 | 29 | content\Net471\web.config.install.xdt 30 | 31 | 32 | content\Net471\app.config.uninstall.xdt 33 | 34 | 35 | content\Net471\web.config.uninstall.xdt 36 | 37 | 38 | tools\Net471\ 39 | 40 | 41 | tools\Net471\ 42 | 43 | 44 | docs\Readme.md 45 | 46 | 47 | images\dotnet-icon.png 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.UserSecrets.nupkg/Microsoft.Configuration.ConfigurationBuilders.UserSecrets.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $NuGetPackageId$ 5 | $NuGetPackageVersion$ 6 | Microsoft 7 | Microsoft 8 | © Microsoft Corporation. All rights reserved. 9 | Microsoft Configuration Builders - UserSecrets 10 | A basic key/value Configuration Builder for the .Net Framework that draws from a a 'secrets' file outside of source control. 11 | A basic key/value Configuration Builder for the .Net Framework that draws from a a 'secrets' file outside of source control. 12 | en-US 13 | https://github.com/aspnet/MicrosoftConfigurationBuilders 14 | images\dotnet-icon.png 15 | https://licenses.nuget.org/MIT 16 | MIT 17 | true 18 | docs\Readme.md 19 | Microsoft Configuration Builders 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.UserSecrets.nupkg/tools/Net471/Install.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | ##### Describe the UserSecrets config builder ##### 9 | $userSecretsId=[Guid]::NewGuid() 10 | $secretsConfigBuilder = [BuilderDescription]@{ 11 | TypeName="$typeName$"; 12 | Assembly="$assemblyName$"; 13 | Version="$assemblyVersion$"; 14 | DefaultName="Secrets"; 15 | AllowedParameters=@( $keyValueCommonParameters + 16 | [ParameterDescription]@{ Name="userSecretsId"; IsRequired=$false; DefaultValue=$userSecretsId }, 17 | [ParameterDescription]@{ Name="userSecretsFile"; IsRequired=$false }); 18 | } 19 | 20 | CommonInstall $secretsConfigBuilder 21 | -------------------------------------------------------------------------------- /src/packages/ConfigurationBuilders.UserSecrets.nupkg/tools/Net471/Uninstall.ps1: -------------------------------------------------------------------------------- 1 | # Copyright (c) .NET Foundation. All rights reserved. 2 | # Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | param($installPath, $toolsPath, $package, $project) 5 | 6 | . "$PSScriptRoot\KeyValueConfigBuildersCommon.ps1" 7 | 8 | CommonUninstall "$typeName$, $assemblyName$" 9 | -------------------------------------------------------------------------------- /src/packages/assets/Readme-Environment.md: -------------------------------------------------------------------------------- 1 | # Environment ConfigBuilder 2 | 3 | This package offers the most basic of the config builders. It draws its values from Environment, and it does not have any additional configuration options. More comprehensive documentation exists at [the MicrosoftConfigBuilders project](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#environmentconfigbuilder). 4 | 5 | The basic usage of this builder is given below. Parameters inside `[]`s are optional. Parameters grouped in `()`s are mutually exclusive. Parameters beginning with `@` allow appSettings substitution. The first line of parameters are common to all builders and optional. Their meaning, usage, and defaults are [documented here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#introduction-to-keyvalue-config-builders). They are grouped on one line for brevity. When a builder uses a different default value than the project default, the differing value is also listed. Builder-specific settings are listed on each line thereafter followed by a brief explanation. 6 | 7 | ```xml 8 | 11 | ``` 12 | 13 | ### V3 Updates: 14 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v3-updates). These are the ones most relevant to this builder: 15 | * :warning: ***Breaking Change*** - `Expand` mode is gone. It has been [replaced by `Token` mode](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#mode). 16 | * `optional` attribute is obsolete => [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute which provides more versatility. (The `optional` attribute is still parsed and recognized in the absence of the newer [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute, but builders should migrate to use the new attribute name when possible. Installation scripts should try to handle this automatically.) 17 | * Character Mapping - Some config builders have had an internal mapping of characters that might exist in keys in the config file but are illegal in keys at the source. As more scenarios come to light and individual prefrences are not always unanimous, V3 instead adds the [`charMap`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#charmap) attribute to allow this character mapping to work with all **KeyValueConfigBuilders** and to be handled in an easily configurable manner. 18 | 19 | ### V2 Updates: 20 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v2-updates). These are the ones most relevant to this builder: 21 | * ConfigBuilder Parameters from AppSettings - This has been one of the most asked for features of these config builders. With V2, it is now possible to read initialization parameters for config builders from `appSettings`. Read more about it [here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#appsettings-parameters). 22 | * **[[Obsolete]] This has been superceded by the [enabled](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) tag.** (~~Base Optional Tag - The `optional` tag that some of the builders in this project employed in V1 has been moved into the base class and is now available on all key/value config builders.~~) 23 | -------------------------------------------------------------------------------- /src/packages/assets/Readme-Json.md: -------------------------------------------------------------------------------- 1 | # SimpleJson ConfigBuilder 2 | 3 | This package provides a config builder that draws its values from Json file. It comes without many frills, but does offer the ability to treat the entire Json file as a single flat config source or as a set of config sources broken into flat sections at the first level. More comprehensive documentation exists at [the MicrosoftConfigBuilders project](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#simplejsonconfigbuilder). 4 | 5 | The basic usage of this builder is given below. Parameters inside `[]`s are optional. Parameters grouped in `()`s are mutually exclusive. Parameters beginning with `@` allow appSettings substitution. The first line of parameters are common to all builders and optional. Their meaning, usage, and defaults are [documented here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#introduction-to-keyvalue-config-builders). They are grouped on one line for brevity. When a builder uses a different default value than the project default, the differing value is also listed. Builder-specific settings are listed on each line thereafter followed by a brief explanation. 6 | 7 | ```xml 8 | 13 | ``` 14 | 15 | ### V3 Updates: 16 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v3-updates). These are the ones most relevant to this builder: 17 | * :warning: ***Breaking Change*** - `Expand` mode is gone. It has been [replaced by `Token` mode](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#mode). 18 | * Json use has migrated to use `System.Text.Json` instead of `Newtonsoft.Json`. 19 | * `optional` attribute is obsolete => [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute which provides more versatility. (The `optional` attribute is still parsed and recognized in the absence of the newer [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute, but builders should migrate to use the new attribute name when possible. Installation scripts should try to handle this automatically.) 20 | 21 | ### V2 Updates: 22 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v2-updates). These are the ones most relevant to this builder: 23 | * ConfigBuilder Parameters from AppSettings - This has been one of the most asked for features of these config builders. With V2, it is now possible to read initialization parameters for config builders from `appSettings`. Read more about it [here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#appsettings-parameters). 24 | * **[[Obsolete]] This has been superceded by the [enabled](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) tag.** (~~Base Optional Tag - The `optional` tag that some of the builders in this project employed in V1 has been moved into the base class and is now available on all key/value config builders.~~) 25 | -------------------------------------------------------------------------------- /src/packages/assets/Readme-KeyPerFile.md: -------------------------------------------------------------------------------- 1 | # KeyPerFile ConfigBuilder 2 | 3 | This package provides a config builder that draws its values from a directory's files as a source of values. A file's name is the key, and the contents are the value. This config builder can be useful when running in an orchestrated container environment, as systems like Docker Swarm and Kubernetes provide 'secrets' to their orchestrated windows containers in this key-per-file manner. More comprehensive documentation exists at [the MicrosoftConfigBuilders project](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#keyperfileconfigbuilder). 4 | 5 | The basic usage of this builder is given below. Parameters inside `[]`s are optional. Parameters grouped in `()`s are mutually exclusive. Parameters beginning with `@` allow appSettings substitution. The first line of parameters are common to all builders and optional. Their meaning, usage, and defaults are [documented here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#introduction-to-keyvalue-config-builders). They are grouped on one line for brevity. When a builder uses a different default value than the project default, the differing value is also listed. Builder-specific settings are listed on each line thereafter followed by a brief explanation. 6 | 7 | ```xml 8 | 14 | ``` 15 | 16 | ### V3 Updates: 17 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v3-updates). These are the ones most relevant to this builder: 18 | * :warning: ***Breaking Change*** - `Expand` mode is gone. It has been [replaced by `Token` mode](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#mode). 19 | * `optional` attribute is obsolete => [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute which provides more versatility. (The `optional` attribute is still parsed and recognized in the absence of the newer [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute, but builders should migrate to use the new attribute name when possible. Installation scripts should try to handle this automatically.) 20 | 21 | ### V2 Updates: 22 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v2-updates). These are the ones most relevant to this builder: 23 | * ConfigBuilder Parameters from AppSettings - This has been one of the most asked for features of these config builders. With V2, it is now possible to read initialization parameters for config builders from `appSettings`. Read more about it [here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#appsettings-parameters). 24 | * **[[Obsolete]] This has been superceded by the [enabled](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) tag.** (~~Base Optional Tag - The `optional` tag that some of the builders in this project employed in V1 has been moved into the base class and is now available on all key/value config builders.~~) 25 | -------------------------------------------------------------------------------- /src/packages/assets/Readme-UserSecrets.md: -------------------------------------------------------------------------------- 1 | # UserSecrets ConfigBuilder 2 | 3 | This package provides a config builder that draws its values from an `Xml` file - usually stored outside of source controll - containing a list of secrets. The secrets file can be configured directly, or it can be specified by a `userSecretsId` which helps to locate the file in a well-known 'UserSecrets' directory. More comprehensive documentation for using this builder exists at [the MicrosoftConfigBuilders project](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#usersecretsconfigbuilder). 4 | 5 | The basic usage of this builder is given below. Parameters inside `[]`s are optional. Parameters grouped in `()`s are mutually exclusive. Parameters beginning with `@` allow appSettings substitution. The first line of parameters are common to all builders and optional. Their meaning and use are [documented at the MicrosoftConfigBuilders project](blob/main/docs/KeyValueConfigBuilders.md#keyvalue-config-builders). Tthey are grouped on one line for brevity. Builder-specific settings are listed on each line thereafter followed by a brief explanation at the end. When a builder uses a different default value than the [MicrosoftConfigBuilders](https://github.com/aspnet/MicrosoftConfigurationBuilders) project as a whole, the differing default is also listed. 6 | 7 | ```xml 8 | 12 | ``` 13 | 14 | * `userSecretsId` - This is the preferred method for identifying an xml secrets file. It works similar to .Net Core, which uses a 'UserSecretsId' project property to store this identifier. With this attribute, the `UserSecretsConfigBuilder` will look in a well-known local location (%APPDATA%\Microsoft\UserSecrets\\<userSecretsId>\secrets.xml in Windows environments) for a secrets file belonging to this identifier. 15 | * `userSecretsFile` - An optional attribute specifying the file containing the secrets. The '~' character can be used at the start to reference the app root. One of this attribute or the 'userSecretsId' attribute is required. If both are specified, 'userSecretsFile' takes precedence. 16 | 17 | ### V3 Updates: 18 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v3-updates). These are the ones most relevant to this builder: 19 | * :warning: ***Breaking Change*** - `Expand` mode is gone. It has been [replaced by `Token` mode](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#mode). 20 | * `optional` attribute is obsolete => [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute which provides more versatility. (The `optional` attribute is still parsed and recognized in the absence of the newer [`enabled`](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) attribute, but builders should migrate to use the new attribute name when possible. Installation scripts should try to handle this automatically.) 21 | 22 | ### V2 Updates: 23 | A more complete list of updates [lives here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/README.md#v2-updates). These are the ones most relevant to this builder: 24 | * ConfigBuilder Parameters from AppSettings - This has been one of the most asked for features of these config builders. With V2, it is now possible to read initialization parameters for config builders from `appSettings`. Read more about it [here](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#appsettings-parameters). 25 | * **[[Obsolete]] This has been superceded by the [enabled](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/docs/KeyValueConfigBuilders.md#enabled) tag.** (~~Base Optional Tag - The `optional` tag that some of the builders in this project employed in V1 has been moved into the base class and is now available on all key/value config builders.~~) 26 | -------------------------------------------------------------------------------- /src/packages/assets/dotnet-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aspnet/MicrosoftConfigurationBuilders/6858f0c496c9ec323ec7358b2dc4eeca77ac9c97/src/packages/assets/dotnet-icon.png -------------------------------------------------------------------------------- /src/packages/packages.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Release 6 | AnyCPU 7 | true 8 | 8.0.30703 9 | 2.0 10 | {7EC5863F-7FF1-41C7-A384-8FFF81531E7A} 11 | SAK 12 | SAK 13 | SAK 14 | SAK 15 | v4.7.1 16 | 17 | 18 | 19 | false 20 | false 21 | 22 | 23 | false 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /test.cmd: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | setlocal 4 | set EnableNuGetPackageRestore=true 5 | 6 | set MSBUILDEXE=msbuild.exe 7 | 8 | set cfgOption=/p:Configuration=Release 9 | REM set cfgOption=/p:Configuration=Debug 10 | REM set cfgOption=/p:Configuration=Debug;Release 11 | if not "%1"=="" set cfgOption=/p:Configuration= 12 | 13 | set logOptions=/v:n /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err 14 | REM set logOptions=/v:diag /flp:Summary;Verbosity=diag;LogFile=msbuild.log /flp1:warningsonly;logfile=msbuild.wrn /flp2:errorsonly;logfile=msbuild.err 15 | 16 | %MSBUILDEXE% "%~dp0\MicrosoftConfigurationBuilders.msbuild" /t:UnitTest %logOptions% /maxcpucount /nodeReuse:false %cfgOption%%* 17 | 18 | endlocal 19 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/EnvironmentTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Specialized; 3 | using System.IO; 4 | using Microsoft.Configuration.ConfigurationBuilders; 5 | using Xunit; 6 | 7 | 8 | namespace Test 9 | { 10 | public class EnvironmentFixture : IDisposable 11 | { 12 | // This doesn't really need to be a Fixtures - since there isn't really any cleanup that has to be done. 13 | // But it does save us from repeated setup, and also matches the pattern we use in the other builder tests. 14 | public EnvironmentFixture() 15 | { 16 | // Populate the environment with key/value pairs that are needed for common tests 17 | foreach (string key in CommonBuilderTests.CommonKeyValuePairs) 18 | Environment.SetEnvironmentVariable(key, CommonBuilderTests.CommonKeyValuePairs[key]); 19 | } 20 | 21 | public void Dispose() { } 22 | } 23 | 24 | public class EnvironmentTests : IClassFixture 25 | { 26 | private readonly EnvironmentFixture _fixture; 27 | 28 | public EnvironmentTests(EnvironmentFixture fixture) 29 | { 30 | _fixture = fixture; 31 | } 32 | 33 | // ====================================================================== 34 | // CommonBuilderTests 35 | // ====================================================================== 36 | [Fact] 37 | public void Environment_GetValue() 38 | { 39 | CommonBuilderTests.GetValue(() => new EnvironmentConfigBuilder(), "EnvGetValue"); 40 | } 41 | 42 | [Fact] 43 | public void Environment_GetAllValues() 44 | { 45 | CommonBuilderTests.GetAllValues(() => new EnvironmentConfigBuilder(), "EnvGetAll"); 46 | } 47 | 48 | [Fact] 49 | public void Environment_ProcessConfigurationSection() 50 | { 51 | // We have to use a prefix to filter out non-related environment variables :/ 52 | CommonBuilderTests.ProcessConfigurationSection(() => new EnvironmentConfigBuilder(), "EnvProcessConfig", 53 | new NameValueCollection() { { "prefix", CommonBuilderTests.CommonKVPrefix } }); 54 | } 55 | 56 | // ====================================================================== 57 | // Environment Parameters 58 | // ====================================================================== 59 | [Fact] 60 | public void Environment_DefaultSettings() 61 | { 62 | var builder = TestHelper.CreateBuilder(() => new EnvironmentConfigBuilder(), "EnvDefault"); 63 | 64 | // Enabled 65 | Assert.Equal(KeyValueEnabled.Optional, builder.Enabled); 66 | 67 | // CharacterMap 68 | Assert.Single(builder.CharacterMap); 69 | Assert.Equal("__", builder.CharacterMap[":"]); 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/MultiThreadingTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.Specialized; 4 | using System.Configuration; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using Microsoft.Configuration.ConfigurationBuilders; 8 | using Xunit; 9 | 10 | namespace Test 11 | { 12 | public class MultiThreadingTests 13 | { 14 | // This test likely produces an uncatchable StackOverflowException when it fails. Beware that 15 | // there likely won't be an explicit failure with this test. More like an 'incomplete.' 16 | [Fact] 17 | public void BigWorkInLazyInitialize_ThreadUsesNotinitializedObject() 18 | { 19 | //Arrange 20 | var builder = new SlowInitConfigBuilder(); 21 | builder.Initialize("test", new NameValueCollection() { { "mode", "Token" } }); 22 | var appSettings = new AppSettingsSection(); 23 | appSettings.Settings.Add("${TestKey1}", "expandTestValue"); 24 | 25 | //Act 26 | var task = Task.Run(() => builder.ProcessConfigurationSection(appSettings)); 27 | var task2 = Task.Run(() => 28 | { 29 | while (!builder.BaseInitialized) { } 30 | 31 | builder.ProcessConfigurationSection(appSettings); 32 | }); 33 | Task.WaitAll(task, task2); 34 | 35 | //Assert 36 | Assert.False(builder.UseOfNotInititializedObject); 37 | } 38 | 39 | class SlowInitConfigBuilder : KeyValueConfigBuilder 40 | { 41 | private Dictionary sourceValues; 42 | 43 | public bool UseOfNotInititializedObject { get; private set; } = false; 44 | public bool BaseInitialized { get; private set; } = false; 45 | 46 | /// 47 | /// Initializes the configuration builder lazily. 48 | /// 49 | /// The friendly name of the provider. 50 | /// A collection of the name/value pairs representing builder-specific attributes specified in the configuration for this provider. 51 | protected override void LazyInitialize(string name, NameValueCollection config) 52 | { 53 | base.LazyInitialize(name, config); 54 | BaseInitialized = true; 55 | 56 | // some big work here 57 | Task.Delay(2000).Wait(); 58 | 59 | sourceValues = new Dictionary(StringComparer.OrdinalIgnoreCase) 60 | { 61 | {"TestKey1", "TestKey1Value"} 62 | }; 63 | } 64 | 65 | public override string GetValue(string key) 66 | { 67 | if (sourceValues == null) 68 | { 69 | UseOfNotInititializedObject = true; 70 | } 71 | return sourceValues.TryGetValue(key, out var value) ? value : null; 72 | } 73 | 74 | public override ICollection> GetAllValues(string prefix) 75 | { 76 | if (sourceValues == null) 77 | { 78 | UseOfNotInititializedObject = true; 79 | } 80 | return sourceValues.Where(s => s.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)).ToList(); 81 | } 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Microsoft.Configuration.ConfigurationBuilders.Test")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("Microsoft")] 9 | [assembly: AssemblyProduct("Microsoft.Configuration.ConfigurationBuilders.Test")] 10 | [assembly: AssemblyCopyright("Copyright © Microsoft 2017")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("9371a23f-bcb8-4429-8652-0a12d43f14f3")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/UtilsTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using Microsoft.Configuration.ConfigurationBuilders; 5 | using Xunit; 6 | 7 | namespace Test 8 | { 9 | public class UtilsTests 10 | { 11 | [Fact] 12 | public void Utils_MapPath() 13 | { 14 | // Not running in ASP.Net 15 | var exception = Record.Exception(() => Utils.MapPath("\"{Very*invalid\\..\\..\\..\\%path&")); 16 | Assert.NotNull(exception); 17 | 18 | // Rooted paths don't change 19 | Assert.Equal(@"C:\Windows\System32", Utils.MapPath(@"C:\Windows\System32")); 20 | Assert.Equal(@"/Windows", Utils.MapPath(@"/Windows")); 21 | Assert.Equal(@"\Windows", Utils.MapPath(@"\Windows")); 22 | 23 | // Relative paths 24 | Assert.Equal(Path.GetFullPath(@"foo\bar\baz"), Utils.MapPath(@"foo\bar\baz")); 25 | Assert.Equal(Path.GetFullPath(@"..\foo\..\baz"), Utils.MapPath(@"..\foo\..\baz")); 26 | 27 | // Home-relative paths 28 | string baseDir = AppDomain.CurrentDomain.BaseDirectory; 29 | Assert.Equal(baseDir, Utils.MapPath(@"~\")); 30 | Assert.Equal(baseDir, Utils.MapPath(@"~/")); 31 | Assert.Equal(Path.Combine(baseDir, @"hello"), Utils.MapPath(@"~/hello")); 32 | Assert.Equal(Path.Combine(baseDir, @"good-bye\"), Utils.MapPath(@"~\good-bye\")); 33 | } 34 | 35 | [Fact] 36 | public void Utils_MapPath_AspNet() 37 | { 38 | try 39 | { 40 | // Fake running in ASP.Net 41 | FakeAspNet(true); 42 | 43 | // Rooted paths don't change 44 | Assert.Equal(@"C:\Windows\System32", Utils.MapPath(@"C:\Windows\System32")); 45 | Assert.Equal(@"/Windows", Utils.MapPath(@"/Windows")); 46 | Assert.Equal(@"\Windows", Utils.MapPath(@"\Windows")); 47 | 48 | // A real HostingEnvironment.MapPath would reject this. But we don't mock all that logic. 49 | // Instead, just verify that we have gone through the ASP.Net HostingEnvironment path. 50 | string badPath = ")*@#__This_is_not_a_valid_Path_and_will_error_Unless_we_Get_into_ServerMapPath()}}}}!"; 51 | Assert.Equal(MockHostingEnvironment.PathPrefix + badPath, Utils.MapPath(badPath)); 52 | } 53 | finally 54 | { 55 | // Stop faking ASP.Net 56 | FakeAspNet(false); 57 | } 58 | } 59 | 60 | [Fact] 61 | public void Utils_MapPath_OpenConfig() 62 | { 63 | var cfg = TestHelper.LoadMultiLevelConfig("empty.config", "customAppSettings.config"); 64 | var appSettings = cfg.AppSettings; 65 | 66 | // Not running in ASP.Net 67 | var exception = Record.Exception(() => Utils.MapPath("\"{Very*invalid\\..\\..\\..\\%path&", appSettings)); 68 | Assert.NotNull(exception); 69 | 70 | // Rooted paths don't change 71 | Assert.Equal(@"C:\Windows\System32", Utils.MapPath(@"C:\Windows\System32", appSettings)); 72 | Assert.Equal(@"/Windows", Utils.MapPath(@"/Windows", appSettings)); 73 | Assert.Equal(@"\Windows", Utils.MapPath(@"\Windows", appSettings)); 74 | 75 | // Relative paths are relative to the config file 76 | string configDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testConfigFiles"); 77 | Assert.Equal(Path.GetFullPath(Path.Combine(configDir, @"foo\bar\baz")), Utils.MapPath(@"foo\bar\baz", appSettings)); 78 | Assert.Equal(Path.GetFullPath(Path.Combine(configDir, @"..\foo\..\baz")), Utils.MapPath(@"..\foo\..\baz", appSettings)); 79 | 80 | // Home-relative paths 81 | string baseDir = AppDomain.CurrentDomain.BaseDirectory; 82 | Assert.Equal(baseDir, Utils.MapPath(@"~\", appSettings)); 83 | Assert.Equal(baseDir, Utils.MapPath(@"~/", appSettings)); 84 | Assert.Equal(Path.Combine(baseDir, @"hello"), Utils.MapPath(@"~/hello", appSettings)); 85 | Assert.Equal(Path.Combine(baseDir, @"good-bye\"), Utils.MapPath(@"~\good-bye\", appSettings)); 86 | } 87 | 88 | private void FakeAspNet(bool isAspNet) 89 | { 90 | // Make sure Utils is static inited. 91 | Utils.MapPath(@"\"); 92 | 93 | // Set that IsAspNet flag appropriately 94 | Type utils = typeof(Utils); 95 | FieldInfo isAspNetField = utils.GetField("s_isAspNet", BindingFlags.Static | BindingFlags.NonPublic); 96 | isAspNetField.SetValue(null, isAspNet); 97 | 98 | // And mock HostingEnvironment? 99 | FieldInfo hostingEnvironment = utils.GetField("s_hostingEnvironmentType", BindingFlags.Static | BindingFlags.NonPublic); 100 | hostingEnvironment.SetValue(null, isAspNet ? typeof(MockHostingEnvironment) : null); 101 | } 102 | 103 | private class MockHostingEnvironment 104 | { 105 | public static string PathPrefix = @"\\MockHE\ASP.Net\"; 106 | public static string MapPath(string path) 107 | { 108 | return PathPrefix + path; 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/customAppSettings.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/empty.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/instance-appexe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/instance-machine.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/recursion-appexe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/recursion-machine.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 |
6 | 7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/simpleJsonConflict.json: -------------------------------------------------------------------------------- 1 | { 2 | "appSettings:conflict": "root of conflict", 3 | "appSettings": { 4 | "conflict": "conflicted complex value" 5 | }, 6 | 7 | "customAppSettings:arrayConflict:0": "root of custom conflict", 8 | "customAppSettings": { 9 | "arrayConflict": [ 1, 2, 3 ], 10 | "arrayConflict:1": "internal array conflict" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/simpleJsonConnStrTest.json: -------------------------------------------------------------------------------- 1 | { 2 | // Comments are not allowed per the Json spec... 3 | // ...but System.Text.Json should handle these gracefully. 4 | 5 | "connStr1": "Just a single string at the root", 6 | "connStr2": { 7 | "randomAttr": "A random attribute isn't actually ignored", 8 | "connectionString": "A value for cs2 from the root", 9 | "providerName": "A value for cs2 provider name from the root" 10 | }, 11 | "connStr3": { 12 | "connectionString": "A value for cs3 from the root - no provider name" 13 | }, 14 | "connStr4:connectionString": "Yes, we can fake it like this in the root", 15 | "aNameFromJson": "Contains_a_${token_value}", 16 | "Contains_a_${token_value}": "Weird double replaced value but not token", 17 | 18 | // ConnectionStrings section 19 | "connectionStrings": { 20 | "connStr1": { 21 | "randomAttr": "Remember this is a flat key/value config source - this random is its own key/value", 22 | "connectionString": "A value for cs1 from the CS subsection", 23 | "providerName": "A value for cs1 provider name from the CS subsection" 24 | }, 25 | "connStr2": { 26 | "connectionString": "A value for cs2 from the CS subsection - no provider name" 27 | }, 28 | "connStr3": "Just a simple CS from the CS subsection", 29 | "connectionString": "This is weird", 30 | "providerName": "Brought to you by weird", 31 | "token_value": "NOT_A_TOKEN_ANYMORE" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/simpleJsonOpenConfigTest.json: -------------------------------------------------------------------------------- 1 | { 2 | // Comments are not allowed per the Json spec... 3 | // ...but System.Text.Json should handle these gracefully. 4 | 5 | "appSettings": { 6 | "strictSetting": "newStrictValue", 7 | "greedySetting": "newGreedyValue", 8 | "csJsonEnabled": "not-enabled-cause-exception" 9 | }, 10 | 11 | // ConnectionStrings section 12 | "connectionStrings": { 13 | "connStr1": "old-style connStr only", 14 | "connStr2": { 15 | "connectionString": "A value for cs2 from the CS subsection", 16 | "providerName": "A value for cs2 provider name from the CS subsection" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/Microsoft.Configuration.ConfigurationBuilders.Test/testConfigFiles/simpleJsonTest.json: -------------------------------------------------------------------------------- 1 | { 2 | // Comments are not allowed per the Json spec... 3 | // ...but System.Text.Json should handle these gracefully. 4 | "rootString": "From Json Root", 5 | "rootBoolean": true, 6 | "rootInteger": 42, 7 | "rootArrayOfStrings": [ "one", "two", "three" ], 8 | "rootArrayOfBooleans": [ true, false ], 9 | "rootArrayOfIntegers": [ 7, 8, 9 ], 10 | "rootMixedArray": [ true, 2, "three" ], 11 | "rootEmptyArray": [], 12 | "rootNull": null, 13 | 14 | // AppSettings section 15 | "appSettings": { 16 | "asString": "From appSettings", 17 | "asBoolean": true, 18 | "asInteger": 1977, 19 | "asArrayOfStrings": [ "four", "five", "six" ], 20 | "asArrayOfBooleans": [ false, false ], 21 | "asArrayOfIntegers": [ 3, 1, 4, 15 ], 22 | "asMixedArray": [ false, 0, "not true" ], 23 | "asEmptyArray": [], 24 | "asNull": null, 25 | // This is complex 26 | "asComplex": { 27 | // Which is why 28 | "cpxString": "From complex part of appSettings", 29 | "cpxBoolean": true, 30 | "cpxInteger": 801, 31 | // it has 32 | "cpxArrayOfStrings": [ "foo", "bar", "baz" ], 33 | "cpxArrayOfBooleans": [ true, true ], 34 | "cpxArrayOfIntegers": [ 35, 5 ], 35 | // many 36 | "cpxMixedArray": [ true, 1, "yes" ], 37 | "cpxEmptyArray": [], 38 | "cpxNull": null 39 | // comments. 40 | } 41 | }, 42 | 43 | // Custom Setting section 44 | "customAppSettings": { 45 | "jsonCustomString": "Custom Setting from Json", 46 | "jsonCustomInteger": 5, 47 | "jsonCustomArray": [ 1, 2, 3 ], 48 | "jsonCustomComplex": { 49 | "setting1": "Complex Setting 1", 50 | "setting2": "Complex Setting 2", 51 | "jsonArrayOfSettings": [ "one", "two", "three" ] 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tools/.verif.whitelist: -------------------------------------------------------------------------------- 1 | *\lib\*\*.xml,ignore xmldoc files -------------------------------------------------------------------------------- /tools/signing.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Microsoft400 8 | MsSharedLib72 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Microsoft400 18 | 19 | 20 | Microsoft400 21 | 22 | 23 | 25 | 27 | 28 | 29 | 30 | 31 | $(PackageOutputDir) 32 | 33 | 34 | 35 | NuGet 36 | 37 | 38 | 39 | 40 | --------------------------------------------------------------------------------