0

I need access on the Up() function to the appsetting from other project.

My problem is that I can not load a constructor in the migration.

public partial class MyMigration : DbMigration {    
    public override void Up() {
         // Here I need access to my appSettings    
    } 
}

1 Answers1

0

Be carrefull with that, not a best practice. You also could have to rollback if you want your init app config back. This link could help you too: How to select different app.config for several build configurations

var path = @"C:\somepath\Configuration\App.config";
string confFolder = Path.GetDirectoryName(path);
var pathFilterRoot = Path.GetPathRoot(confFolder);
string configFileToOPen = Path.GetFileName(pathFilterRoot);

ExeConfigurationFileMap fileMapConfig = new ExeConfigurationFileMap  {
    ExeConfigFilename = Path.Combine(Path.GetFullPath(pathFilterRoot + "\\" + configFileToOPen))
};

System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMapConfig, ConfigurationUserLevel.None);
LeBigCat
  • 1,737
  • 1
  • 11
  • 16