Skip to content

Commit

Permalink
Tools: Fix up App.config path on .NET Framework
Browse files Browse the repository at this point in the history
Fixes #19760
  • Loading branch information
bricelam committed Jul 14, 2020
1 parent 9e5734e commit bbe1a69
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ef/Commands/ProjectCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.EntityFrameworkCore.Tools.Properties;

#if NET461
using System.Configuration;
#endif

namespace Microsoft.EntityFrameworkCore.Tools.Commands
{
internal abstract class ProjectCommandBase : EFCommandBase
Expand Down Expand Up @@ -60,6 +64,27 @@ protected IOperationExecutor CreateExecutor()
}
catch (MissingMethodException) // NB: Thrown with EF Core 3.1
{
var configurationFile = (_startupAssembly.Value() ?? _assembly.Value()) + ".config";
if (File.Exists(configurationFile))
{
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", configurationFile);
try
{
typeof(ConfigurationManager)
.GetField("s_initState", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, 0);
typeof(ConfigurationManager)
.GetField("s_configSystem", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, null);
typeof(ConfigurationManager).Assembly
.GetType("System.Configuration.ClientConfigPaths")
.GetField("s_current", BindingFlags.Static | BindingFlags.NonPublic)
.SetValue(null, null);
}
catch
{
}
}
}
#elif !NETCOREAPP2_0
#error target frameworks need to be updated.
Expand Down
1 change: 1 addition & 0 deletions src/ef/ef.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Configuration" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit bbe1a69

Please sign in to comment.