Skip to content

Commit 27d5aed

Browse files
authored
Merge pull request #2110 from EPPlusSoftware/fix/removoved-configmanager
Removed change for ConfigurationManager in .NET 8/9 and .NET Standard
2 parents 1863f5e + e4dba07 commit 27d5aed

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

src/Directory.Packages.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<PackageVersion Include="System.Security.Cryptography.Xml" Version="8.0.2" />
1414
<PackageVersion Include="System.Text.Encoding.CodePages" Version="8.0.0" />
1515
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
16-
<PackageVersion Include="System.Configuration.ConfigurationManager" version="8.0.1" />
1716
</ItemGroup>
1817
<ItemGroup>
1918
<PackageVersion Include="FakeItEasy" Version="8.0.0" />

src/EPPlus/EPPlus.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,6 @@
698698
<PackageReference Include="System.ComponentModel.Annotations" />
699699
<PackageReference Include="System.Text.Encoding.CodePages" />
700700
<PackageReference Include="System.Security.Cryptography.Xml" />
701-
<PackageReference Include="System.Configuration.ConfigurationManager" />
702701
</ItemGroup>
703702

704703
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
@@ -708,7 +707,6 @@
708707
<PackageReference Include="System.ComponentModel.Annotations" />
709708
<PackageReference Include="System.Text.Encoding.CodePages" VersionOverride="9.0.3"/>
710709
<PackageReference Include="System.Security.Cryptography.Xml" VersionOverride="9.0.3"/>
711-
<PackageReference Include="System.Configuration.ConfigurationManager" VersionOverride="9.0.8" />
712710
</ItemGroup>
713711

714712
<ItemGroup>

src/EPPlus/EPPlusLicense.cs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class EPPlusLicense
2424
/// <summary>
2525
/// The name used for a commercial organization
2626
/// </summary>
27-
public string LegalName
27+
public string LegalName
2828
{
2929
get;
3030
private set;
@@ -100,17 +100,17 @@ public void SetNonCommercialOrganization(string organizationName)
100100

101101
private bool ValidateName(string name, out string msg)
102102
{
103-
if(name.Length < 3)
103+
if (name.Length < 3)
104104
{
105105
msg = "The license holder name must be at least 3 characters.";
106106
return false;
107107
}
108-
if (name.Any(c => c=='/' || c=='\\' || c=='*' || char.IsControl(c) || c=='\t'))
108+
if (name.Any(c => c == '/' || c == '\\' || c == '*' || char.IsControl(c) || c == '\t'))
109109
{
110110
msg = "The license holder name contains invalid characters";
111111
return false;
112112
}
113-
if(name.Count(x=>char.IsLetter(x)) < 2)
113+
if (name.Count(x => char.IsLetter(x)) < 2)
114114
{
115115
msg = "The license holder name contains to few letters.";
116116
return false;
@@ -136,9 +136,9 @@ public void SetCommercial(string licenseKey)
136136
LicenseKey = licenseKey;
137137
LicenseType = EPPlusLicenseType.Commercial;
138138
Source = EPPlusLicenseSource.Code;
139-
if(_licenseSet==false)
139+
if (_licenseSet == false)
140140
{
141-
if(licenseInfo.Status==EPPlusLicenseStatus.InvalidLicenseKey)
141+
if (licenseInfo.Status == EPPlusLicenseStatus.InvalidLicenseKey)
142142
{
143143
throw new InvalidLicenseKeyException(msg);
144144
}
@@ -161,7 +161,7 @@ internal bool SetLicenseFromConfig(List<ExcelInitializationError> initErrors)
161161
else
162162
{
163163
v = v.Trim();
164-
var s = v.Split([':',',']);
164+
var s = v.Split([':', ',']);
165165
if (s[0].Equals("noncommercialorganization", StringComparison.OrdinalIgnoreCase))
166166
{
167167
if (s.Length == 1)
@@ -189,7 +189,7 @@ internal bool SetLicenseFromConfig(List<ExcelInitializationError> initErrors)
189189
{
190190
if (s.Length > 1 && v.StartsWith("commercial", StringComparison.OrdinalIgnoreCase))
191191
{
192-
v = v.Substring(v.IndexOfAny([':',',']) + 1);
192+
v = v.Substring(v.IndexOfAny([':', ',']) + 1);
193193
}
194194
SetCommercial(v.Trim());
195195
ExcelPackage.License.Source = inEnvironment ? EPPlusLicenseSource.EnvironmentVariable : EPPlusLicenseSource.ConfigFile;
@@ -212,16 +212,14 @@ private static string GetConfigValue(string key, List<ExcelInitializationError>
212212
{
213213
#if (Core)
214214
v = ExcelConfigurationReader.GetJsonConfigValue($"EPPlus:ExcelPackage:{key}", _configuration, initErrors);
215-
#endif
216-
if (string.IsNullOrEmpty(v))
217-
{
218215

216+
#else
219217
v = ExcelConfigurationReader.GetValueFromAppSettings($"EPPlus:ExcelPackage:{key}", _configuration, initErrors);
220-
}
221-
if(string.IsNullOrEmpty(v))
222-
{
223-
v = ExcelConfigurationReader.GetValueFromAppSettings($"EPPlus:ExcelPackage.{key}", _configuration, initErrors);
224-
}
218+
if(string.IsNullOrEmpty(v))
219+
{
220+
v = ExcelConfigurationReader.GetValueFromAppSettings($"EPPlus:ExcelPackage.{key}", _configuration, initErrors);
221+
}
222+
#endif
225223
inEnvironment = false;
226224
}
227225
else
@@ -239,7 +237,7 @@ public void RemoveActiveLicense()
239237
LicenseKey = null;
240238
Source = null;
241239
LegalName = null;
242-
LicenseInfo = null;
240+
LicenseInfo = null;
243241
_licenseSet = false;
244242
}
245243
}

src/EPPlus/ExcelConfigurationReader.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ Date Author Change
1212
*************************************************************************************************/
1313
#if (Core)
1414
using Microsoft.Extensions.Configuration;
15+
#else
16+
using System.Configuration;
1517
#endif
16-
using Config=System.Configuration;
1718
using OfficeOpenXml.Configuration;
1819
using System;
1920
using System.Collections.Generic;
21+
using System.IO;
22+
using System.Linq;
23+
using System.Text;
2024

2125
namespace OfficeOpenXml
2226
{
@@ -62,7 +66,7 @@ internal static string GetJsonConfigValue(string key, ExcelPackageConfiguration
6266
var configRoot = default(IConfigurationRoot);
6367
try
6468
{
65-
69+
6670
var build = new ConfigurationBuilder()
6771
.SetBasePath(basePath)
6872
.AddJsonFile(configFileName, true, false);
@@ -104,13 +108,13 @@ internal static string GetJsonConfigValue(string key, ExcelPackageConfiguration
104108
}
105109
#endif
106110

111+
#if (!Core)
107112
internal static string GetValueFromAppSettings(string key, ExcelPackageConfiguration config, List<ExcelInitializationError> initErrors)
108113
{
109114
var supressInitExceptions = config.SuppressInitializationExceptions;
110115
try
111116
{
112-
113-
return Config.ConfigurationManager.AppSettings[key];
117+
return ConfigurationManager.AppSettings[key];
114118
}
115119
catch(Exception ex)
116120
{
@@ -124,5 +128,6 @@ internal static string GetValueFromAppSettings(string key, ExcelPackageConfigura
124128
throw;
125129
}
126130
}
131+
#endif
127132
}
128133
}

0 commit comments

Comments
 (0)