1- // Windows-only: Enables gcServer in the local .dotnet SDK testhost app.config and prints the SDK version.
1+ // Windows-only: Enables gcServer in the local .dotnet SDK testhost app.config files and prints the SDK version.
22// What it does:
33// 1) Finds the repo-local .dotnet folder by walking up from this script's directory.
44// 2) Runs .dotnet\dotnet.exe --version to get the SDK version and prints it.
5- // 3) Locates .dotnet\sdk\{version}\TestHostNetFramework\testhost.net472.exe.config and ensures
6- // <runtime><gcServer enabled="true"/></runtime> is present, then saves the file.
5+ // 3) Locates both
6+ // - .dotnet\sdk\{version}\TestHostNetFramework\testhost.net472.exe.config and
7+ // - .dotnet\sdk\{version}\TestHostNetFramework\testhost.net472.x86.exe.config
8+ // and ensures <runtime><gcServer enabled="true"/></runtime> is present, then saves the files.
79// Usage (from repo root): dotnet fsi eng/update-testhost-gcserver.fsx
810
911open System
@@ -68,45 +70,56 @@ match findDotnetRoot startDir with
6870 // Print the SDK version
6971 printfn " %s " version
7072
71- // Locate the specified config file and ensure gcServer is enabled
72- let cfgPath =
73- Path.Combine ( dotnetRoot , " sdk " , version , " TestHostNetFramework " , " testhost.net472.exe.config" )
73+ // Locate both config files and ensure gcServer is enabled
74+ let cfgFileNames =
75+ [| " testhost.net472.x86.exe.config " ; " testhost.net472.exe.config" |]
7476
75- if not ( File.Exists cfgPath) then
76- eprintfn " Error: Config file not found: %s " cfgPath
77- exit 2
78-
79- // Update the XML config: ensure <runtime><gcServer enabled="true"/></runtime>
80- let doc = System.Xml.Linq.XDocument.Load( cfgPath)
8177 let xn name = System.Xml.Linq.XName.Get( name)
8278
83- let configuration =
84- match doc.Element( xn " configuration" ) with
85- | null ->
86- let root = System.Xml.Linq.XElement( xn " configuration" )
87- doc.Add( root)
88- root
89- | r -> r
90-
91- let runtime =
92- match configuration.Element( xn " runtime" ) with
93- | null ->
94- let r = System.Xml.Linq.XElement( xn " runtime" )
95- configuration.Add( r)
96- r
97- | r -> r
98-
99- let gcServerEl =
100- match runtime.Element( xn " gcServer" ) with
101- | null ->
102- let el = System.Xml.Linq.XElement( xn " gcServer" )
103- el.SetAttributeValue( xn " enabled" , " true" )
104- runtime.Add( el)
105- el
106- | el ->
107- el.SetAttributeValue( xn " enabled" , " true" )
108- el
109-
110- doc.Save( cfgPath)
111- printfn " Updated: %s (gcServer enabled=true)" cfgPath
112- exit 0
79+ let updateOne ( path : string ) =
80+ if not ( File.Exists path) then
81+ false
82+ else
83+ let doc = System.Xml.Linq.XDocument.Load( path)
84+
85+ let configuration =
86+ match doc.Element( xn " configuration" ) with
87+ | null ->
88+ let root = System.Xml.Linq.XElement( xn " configuration" )
89+ doc.Add( root)
90+ root
91+ | r -> r
92+
93+ let runtime =
94+ match configuration.Element( xn " runtime" ) with
95+ | null ->
96+ let r = System.Xml.Linq.XElement( xn " runtime" )
97+ configuration.Add( r)
98+ r
99+ | r -> r
100+
101+ match runtime.Element( xn " gcServer" ) with
102+ | null ->
103+ let el = System.Xml.Linq.XElement( xn " gcServer" )
104+ el.SetAttributeValue( xn " enabled" , " true" )
105+ runtime.Add( el)
106+ | el ->
107+ el.SetAttributeValue( xn " enabled" , " true" )
108+
109+ doc.Save( path)
110+ printfn " Updated: %s (gcServer enabled=true)" path
111+ true
112+
113+ let cfgPaths =
114+ cfgFileNames
115+ |> Array.map ( fun f -> Path.Combine( dotnetRoot, " sdk" , version, " TestHostNetFramework" , f))
116+
117+ let results = cfgPaths |> Array.map updateOne
118+ let updatedCount = results |> Array.filter id |> Array.length
119+
120+ if updatedCount = 0 then
121+ // Fail only if none of the expected files were found
122+ eprintfn " Error: None of the expected config files were found:\n %s " ( String.Join( " \n " , cfgPaths))
123+ exit 2
124+ else
125+ exit 0
0 commit comments