Where Is Machine.Config?
Asked Answered
P

9

477

I want to apply a change so That I can use Server GC settings for my C# 3.5 app - I can do that by editing the machine.config file.

The only problem is I do not know where that is.

How can I find the path of this file in a repeatable way across a number of different machines

Parnas answered 24/2, 2010 at 11:16 Comment(0)
T
640

32-bit

%windir%\Microsoft.NET\Framework\[version]\config\machine.config

64-bit

%windir%\Microsoft.NET\Framework64\[version]\config\machine.config 

[version] should be equal to v1.0.3705, v1.1.4322, v2.0.50727 or v4.0.30319.

v3.0 and v3.5 just contain additional assemblies to v2.0.50727 so there should be no config\machine.config. v4.5.x and v4.6.x are stored inside v4.0.30319.

Trimble answered 24/2, 2010 at 11:18 Comment(9)
It's probably worth mentioning the only two [version] directories you'll find a machine.config in is v2.0.50727 and v4.0.30319, since v3.0 and v3.5 use the .NET 2.0 CLR and v4.5.x are drop in replacements so don't have their own framework directories. Oh, and if you're unlucky enough to still be using .NET 1.1 then there may be a Framework/v1.1.4322 directory.Pyromorphite
@ScottLerch That is not true on my system. There is v1.0.3705, v1.1.4322, v2.0.50727, v3.0, v3.5, and v4.0.30319Antic
@KevinPanko yeah, I already mentioned the caveat about 1.1 but should have also mentioned 1.0 as well... just haven't had to deal with either of those in a long time. You shouldn't find a machine.config in your v3.0 or v3.5 directories though, if you do then I have no idea why.Pyromorphite
Remember to open .config files with a notepad being run as administrator so when you save something system does not save your changes in wrong folder based on 32 or 64 bit.Durant
@AfshinTeymoori I'm not 100% sure but if you run notepad in non admin mode you should not be able to save any changes at all as you don't have write access to the file? (also if you run in admin or not should not change if you save in 32 or 64 bit).Trimble
@Trimble yes you'r right. However, I assumed one is going to make changes in machine.config file where working in a 64 bit windows.Durant
I'm using a hosted site, is the machine.config usually accessible on hosted sites, and how can I modify it if not?Wealthy
@Wealthy if you don't have access to the system drive then you wont be able to modify machine.config, the only way is to contact the hosting provider (but my guess is that even that wont help)Trimble
am i supposed to deal with a dozen of machine.config files?Dilapidate
C
104

You can run this in powershell:

[System.Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile

Which outputs this for .net 4:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config

Note however that this might change depending on whether .net is running as 32 or 64 bit which will result in \Framework\ or \Framework64\ respectively.

Catamenia answered 22/1, 2013 at 5:23 Comment(2)
In PowerShell, you can omit the "System." and just use [Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile. (Also that is specifically the 32-bit path for .NET 4.0. 64-bit is in …\Framework64\… #pedantry)Jedthus
Note that this will return 64-bit path if you're running 64-bit PowerShell.Rios
A
45

In order to be absolutely sure, slap a Label on an ASP.NET page and run this code:

labelDebug.Text = System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile;

I believe this will leave no doubt!

Allomerism answered 10/6, 2011 at 20:3 Comment(1)
Or run this in powershell [System.Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFileCatamenia
C
16

It semi-depends though... mine is:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG

and

C:\Windows\Microsoft.NET\Framework64\v2.0.50727\CONFIG

Claudine answered 24/2, 2010 at 11:20 Comment(0)
A
4
  1. Open Windows Run command. Shortcut=> windows key + r
  2. Type "microsoft.net" - MS .Net folder opens up
  3. Open "Framework"/"Framework64" folder(based on your processor).
  4. Select specific FW version folder e.g. "v4.0.30319"
  5. Open config folder
  6. Machine.config will be available there. Cheers.
Ascertain answered 1/6, 2018 at 2:37 Comment(0)
L
3

C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG

Langobard answered 24/2, 2010 at 11:20 Comment(0)
O
1

In your asp.net app use this

using System.Configuration;
Response.Write(ConfigurationManager.OpenMachineConfiguration().FilePath);
Oakleil answered 12/10, 2015 at 3:33 Comment(0)
E
1

This is a late reply, but if anyone is still looking to open machine.config and view/update configs, here's an example with IIS config using powershell

$machineConfig = [System.Configuration.ConfigurationManager]::OpenMachineConfiguration()

$deployment = $machineConfig.GetSection("system.web/deployment")

$deplyment.Retail = $true

$machineconfig.save()
Eternal answered 14/3, 2021 at 17:56 Comment(0)
M
-2

You can run this in powershell: copy & paste in power shell [System.Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile

mine output is: C:\Windows\Microsoft.NET\Framework\v2.0.50527\config\machine.config

Meathead answered 16/4, 2017 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.