views:

731

answers:

3

Has anyone worked out how to get PowerShell to use app.config files? I have a couple of .NET DLL's I'd like to use in one of my scripts but they expect their own config sections to be present in app.config/web.config.

@Steve/Sam: I had a horrible feeling those were going to be the answers.

Thanks Kev

+4  A: 

I'm guessing that the settings would have to be in powershell.exe.config in the powershell directory, but that seems to be a bad way of doing things.

You can use ConfigurationManager.OpenMappedExeConfiguration to open a configuration file based on the executing DLL name, rather than the application exe, but this would obviously require changes to the DLLs.

samjudson
+3  A: 

Sam's answer is what I had to do when I was writing cmdlets for PolyMon. I haven't found another workaround yet.

Steven Murawski
+3  A: 

I had the same problem, and resolved it using Keith Hill's parser, available here.

fatcat1111