c# - Access to .config files in Roslyn REPL -
using roslyn june 2012 ctp:
is there way provide roslyn c# interactive/repl .config file code being explored? simple example scenario code depends on connection string obtain app.config/web.config.
this possible (and may have been @ time question asked). create loadconfig.csx file following:
#r "system.configuration" using system; using system.io; using system.linq; var paths = new[] { path.combine(environment.currentdirectory, "web.config"), path.combine(environment.currentdirectory, "app.config") }; var configpath = paths.firstordefault(p => file.exists(p)); if (configpath != null) appdomain.currentdomain.setdata("app_config_file", configpath); save file somewhere you'll remember , return project want load in visual studio. right click project , select "reset c# interactive project". once c# interactive window finished loading call:
#load "c:\path\to\loadconfig.csx" note: must call after loading project. if configuration lookups occur before load script script fail work.
now c# interactive window should have access project settings.
Comments
Post a Comment