Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion samples/SampleWebApp/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- <add name="Environment" mode="Expand" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment, Version=1.0.0.0, Culture=neutral"/> -->
<add name="Secrets" userSecretsFile="~/App_Data/secrets.xml" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.UserSecretsConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.UserSecrets, Version=1.0.0.0, Culture=neutral" />
<add name="SimpleJson" jsonFile="~/App_Data/settings.json" ignoreMissingFile="true" type="Microsoft.Configuration.ConfigurationBuilders.SimpleJsonConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Json, Version=1.0.0.0, Culture=neutral" />
<add name="KeyPerFile" directoryPath="~/../KeyPerFileSampleRoot" mode="Greedy" keyDelimiter="--" type="Microsoft.Configuration.ConfigurationBuilders.KeyPerFileConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.KeyPerFile, Version=1.0.0.0, Culture=neutral" />
<add name="KeyPerFile" directoryPath="~/../KeyPerFileSampleRoot" mode="Strict" keyDelimiter="--" type="Microsoft.Configuration.ConfigurationBuilders.KeyPerFileConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.KeyPerFile, Version=1.0.0.0, Culture=neutral" />
Copy link
Contributor

Choose a reason for hiding this comment

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

For my understanding, this is changed only for your testing purpose, correct?

</builders>
</configBuilders>

Expand All @@ -32,6 +32,10 @@
<add key="jsonConnectionString1" value="WILL be replaced by 'SimpleJson' in 'Flat' jsonMode." />
<add key="jsonConnectionString2" value="WILL NOT be replaced by 'SimpleJson' in 'Sectional' jsonMode." />
<add key="jsonCustomSetting1" value="Will be replaced by 'SimpleJson' with prefix='customSettings:' and stripPrefix='true'." />
<add key="SecretFromFile1" value="This will be replaced by KeyPerFile." />
<add key="SECRETFROMFILE2" value="As will this one." />
<add key="SubFeature--FeatureSecretA" value="This will be replaced by KeyPerFile if keyDelimiter is set to '--'." />
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please more specific and point out as File1? This could be confusing and leading to confusion

<add key="ignore.secretfromfile3" value="This value should be left alone." />
</appSettings>

<connectionStrings configBuilders="SimpleJson">
Expand Down
19 changes: 14 additions & 5 deletions src/KeyPerFile/KeyPerFileConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,19 @@ public override ICollection<KeyValuePair<string, string>> GetAllValues(string pr
/// <returns>The value corresponding to the given 'key' or null if no value is found.</returns>
public override string GetValue(string key)
{
if (_allValues != null && _allValues.TryGetValue(key, out string val))
return val;
string filename = key;
if (!String.IsNullOrEmpty(KeyDelimiter))
filename = filename.Replace(KeyDelimiter, Path.DirectorySeparatorChar.ToString());

return null;
if (!String.IsNullOrWhiteSpace(IgnorePrefix))
{
foreach (var pathPart in filename.Split(new char[] { Path.DirectorySeparatorChar })) {
if (pathPart.StartsWith(IgnorePrefix, StringComparison.OrdinalIgnoreCase))
return null;
}
}

return ReadValueFromFile(Path.Combine(DirectoryPath, filename));
}

private IDictionary<string, string> ReadAllValues(string root, string prefix, IDictionary<string, string> values)
Expand All @@ -107,7 +116,7 @@ private IDictionary<string, string> ReadAllValues(string root, string prefix, ID
{
foreach (var sub in di.EnumerateDirectories())
{
if (!String.IsNullOrWhiteSpace(IgnorePrefix) && sub.Name.StartsWith(IgnorePrefix))
if (!String.IsNullOrWhiteSpace(IgnorePrefix) && sub.Name.StartsWith(IgnorePrefix, StringComparison.OrdinalIgnoreCase))
continue;

ReadAllValues(sub.FullName, sub.Name + KeyDelimiter, values);
Expand All @@ -116,7 +125,7 @@ private IDictionary<string, string> ReadAllValues(string root, string prefix, ID

foreach (var file in di.EnumerateFiles())
{
if (!String.IsNullOrWhiteSpace(IgnorePrefix) && file.Name.StartsWith(IgnorePrefix))
if (!String.IsNullOrWhiteSpace(IgnorePrefix) && file.Name.StartsWith(IgnorePrefix, StringComparison.OrdinalIgnoreCase))
continue;

string key = prefix + file.Name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<NuGetContent Include="..\ConfigurationBuilders.Base.nupkg\shared\tools\Net471\pp\*.ps1">
<Destination>tools\Net471\</Destination>
</NuGetContent>
<NuGetContent Include="README.txt">
<Destination>README.txt</Destination>
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
</Project>
24 changes: 24 additions & 0 deletions src/packages/ConfigurationBuilders.Azure.nupkg/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
########################################################################################################################
## ##
## Microsoft.Configuration.ConfigurationBuilders.Azure ##
## ##
########################################################################################################################

WARNING: Double check config builder attributes in your configuraiton files. Some attributes may have been changed
when upgrading this package.

If this is the first time you are installing this configuration builder into your
project, feel free to click the 'X' on this tab to close and continue on.

However, if you are updating this package from a version earlier than 1.0.2... you may want to double check the
declarations for your config builders, because we might have lost changes you made to the default declarations
that were created during the original install.

The upgrade mechanism for nuget is actually just Uninstall/Install, and prior to 1.0.2, this package would delete
the config builder declaration that it created upon install. Makes sense. But if you made any changes to that
declaration without changing the name of it, we didn't bother to make note of that. So the 'install' phase of
updating will declare the default config builder with the default parameters again. (If you did change the name
to something other than the default - AzureKeyVault - then we did not delete your declaration when uninstalling.)

Starting in version 1.0.2, we have a way to stash old declarations aside and restore them upon install. Sorry for the
inconvenience. There should be no such troubles with future upgrades.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<NuGetContent Include="..\ConfigurationBuilders.Base.nupkg\shared\tools\Net471\pp\*.ps1">
<Destination>tools\Net471\</Destination>
</NuGetContent>
<NuGetContent Include="README.txt">
<Destination>README.txt</Destination>
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
</Project>
24 changes: 24 additions & 0 deletions src/packages/ConfigurationBuilders.Environment.nupkg/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
########################################################################################################################
## ##
## Microsoft.Configuration.ConfigurationBuilders.Environment ##
## ##
########################################################################################################################

WARNING: Double check config builder attributes in your configuraiton files. Some attributes may have been changed
when upgrading this package.

If this is the first time you are installing this configuration builder into your
project, feel free to click the 'X' on this tab to close and continue on.

However, if you are updating this package from a version earlier than 1.0.2... you may want to double check the
declarations for your config builders, because we might have lost changes you made to the default declarations
that were created during the original install.

The upgrade mechanism for nuget is actually just Uninstall/Install, and prior to 1.0.2, this package would delete
the config builder declaration that it created upon install. Makes sense. But if you made any changes to that
declaration without changing the name of it, we didn't bother to make note of that. So the 'install' phase of
updating will declare the default config builder with the default parameters again. (If you did change the name
to something other than the default - Environment - then we did not delete your declaration when uninstalling.)

Starting in version 1.0.2, we have a way to stash old declarations aside and restore them upon install. Sorry for the
inconvenience. There should be no such troubles with future upgrades.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<NuGetContent Include="..\ConfigurationBuilders.Base.nupkg\shared\tools\Net471\pp\*.ps1">
<Destination>tools\Net471\</Destination>
</NuGetContent>
<NuGetContent Include="README.txt">
<Destination>README.txt</Destination>
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
</Project>
24 changes: 24 additions & 0 deletions src/packages/ConfigurationBuilders.Json.nupkg/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
########################################################################################################################
## ##
## Microsoft.Configuration.ConfigurationBuilders.Json ##
## ##
########################################################################################################################

WARNING: Double check config builder attributes in your configuraiton files. Some attributes may have been changed
when upgrading this package.

If this is the first time you are installing this configuration builder into your
project, feel free to click the 'X' on this tab to close and continue on.

However, if you are updating this package from a version earlier than 1.0.2... you may want to double check the
declarations for your config builders, because we might have lost changes you made to the default declarations
that were created during the original install.

The upgrade mechanism for nuget is actually just Uninstall/Install, and prior to 1.0.2, this package would delete
the config builder declaration that it created upon install. Makes sense. But if you made any changes to that
declaration without changing the name of it, we didn't bother to make note of that. So the 'install' phase of
updating will declare the default config builder with the default parameters again. (If you did change the name
to something other than the default - SimpleJson - then we did not delete your declaration when uninstalling.)

Starting in version 1.0.2, we have a way to stash old declarations aside and restore them upon install. Sorry for the
inconvenience. There should be no such troubles with future upgrades.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<NuGetContent Include="..\ConfigurationBuilders.Base.nupkg\shared\tools\Net471\pp\*.ps1">
<Destination>tools\Net471\</Destination>
</NuGetContent>
<NuGetContent Include="README.txt">
<Destination>README.txt</Destination>
</NuGetContent>
</ItemGroup>
<Import Project="$(RepositoryRoot)Tools\NuGetProj.targets"/>
</Project>
41 changes: 41 additions & 0 deletions src/packages/ConfigurationBuilders.UserSecrets.nupkg/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
########################################################################################################################
## ##
## Microsoft.Configuration.ConfigurationBuilders.UserSecrets ##
## ##
########################################################################################################################

WARNING: Double check config builder attributes in your configuraiton files. Some attributes may have been changed
when upgrading this package.

If this is the first time you are installing this configuration builder into your
project, feel free to click the 'X' on this tab to close and continue on.

However, if you are updating this package from a version earlier than 1.0.2... you may want to double check the
declarations for your config builders, because we might have lost changes you made to the default declarations
that were created during the original install.

The upgrade mechanism for nuget is actually just Uninstall/Install, and prior to 1.0.2, this package would delete
the config builder declaration that it created upon install. Makes sense. But if you made any changes to that
declaration without changing the name of it, we didn't bother to make note of that. So the 'install' phase of
updating will declare the default config builder with the default parameters again. (If you did change the name
to something other than the default - Secrets - then we did not delete your declaration when uninstalling.)

Starting in version 1.0.2, we have a way to stash old declarations aside and restore them upon install. Sorry for the
inconvenience. There should be no such troubles with future upgrades.


########################################################################################################################


In addition to the upgrade trouble mentioned above, we have also made changes to the UserSecrets package specifically.
We no longer create an empty secrets file, nor do we add a link under 'Properties' to the empty secrets file that we
no longer create. And we do not install any .targets/.props files to magically read $(UserSecretsId) from project
settings at compile-time.

Why? Because Visual Studio will handle these things for you. Similar to the ASP.Net Core User Secrets experience, VS
will have a contextual "Manage User Secrets..." option for your Web Forms projects. Using that will install this
package, create the empty secrets file, and open it for editing. So you will use that menu item instead of seeing
a project item for secrets.

Also, the first and final word on UserSecretsId is what is set in the builder declaration. No more cumbersome
attempts at using project properties in configuration at runtime. Now, what you see (in *.config) is what you get. :)
6 changes: 6 additions & 0 deletions src/packages/packages.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@
<None Include="ConfigurationBuilders.Json.nupkg\tools\Net471\Install.ps1" />
<None Include="ConfigurationBuilders.Json.nupkg\tools\Net471\Uninstall.ps1" />
</ItemGroup>
<ItemGroup>
<Content Include="ConfigurationBuilders.Azure.nupkg\README.txt" />
<Content Include="ConfigurationBuilders.Environment.nupkg\README.txt" />
<Content Include="ConfigurationBuilders.Json.nupkg\README.txt" />
<Content Include="ConfigurationBuilders.UserSecrets.nupkg\README.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="Build">
<MSBuild Projects="@(NuGetProject)" Targets="Build" />
Expand Down