How do I open the machine.config from .NET v2.0.50727
-
27-10-2019 - |
Pergunta
The application I want to read settings from writes to the section of the machine.config in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG.
But when I use the following code:
Configuration myMC = WebConfigurationManager.OpenMachineConfiguration();
Console.WriteLine(myMC.FilePath.ToString());
The path returned is always the .NET 4 machine.config:
c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
Edit: my app uses MEF, so it requires .NET 4, writing the app from .NET 2 is not an option.
Solução
You can open it as an xml or text file, see: http://support.microsoft.com/kb/307548
You could create a service that runs in .net 2.0, and call that service from your .net 4.0 app.
But why do you need to do this?
Outras dicas
It turns out that there is a way to specify which machine.config to open with a ConfigurationManager:
ConfigurationFileMap myCFM = new ConfigurationFileMap(fPath);
Configuration myMC = ConfigurationManager.OpenMappedMachineConfiguration(myCFM);
Console.WriteLine(myMC.FilePath.ToString());
where fPath was the Path to the one I wanted. I got that by digging through the registry.