Skip to content

Commit fedcc23

Browse files
add build target to run IISExpress to host the documentation and open it in browser:
> build ServeDocs
1 parent a329cae commit fedcc23

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

build.fsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#r @"packages/build/FAKE/tools/FakeLib.dll"
66
#load "tools/fakexunithelper.fsx" // helper for xunit 1 is gone, work around by having our own copy for now
7+
#load "tools/fakeiisexpress.fsx" // helper for iisexpress is not ready, work around by having our own copy for now
78

89
open System
910
open System.IO
@@ -191,6 +192,11 @@ Target.create "GenerateDocs" (fun _ ->
191192
Fake.FSIHelper.executeFSIWithArgs "docs/tools" "generate.fsx" ["--define:RELEASE"] [] |> ignore
192193
)
193194

195+
Target.create "ServeDocs" (fun _ ->
196+
Fakeiisexpress.HostStaticWebsite id (__SOURCE_DIRECTORY__ @@ @"docs\output\") |> ignore
197+
Fakeiisexpress.OpenUrlInBrowser "http://localhost:8080"
198+
)
199+
194200
Target.create "ReleaseDocs" (fun _ ->
195201
Repository.clone "" (gitHome + "/" + gitName + ".git") "temp/gh-pages"
196202
Branches.checkoutBranch "temp/gh-pages" "gh-pages"

tools/fakeiisexpress.fsx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// https://github.com/fsharp/FAKE/blob/e1378887c41c37d425e134f83424424b76781228/src/legacy/Fake.IIS/IISExpress.fs
2+
// added HostStaticWebsite
3+
#r "System.Xml.Linq"
4+
open Fake
5+
/// Contains tasks to host webprojects in IIS Express.
6+
//[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
7+
//module Fake.IISExpress
8+
9+
open System.Diagnostics
10+
open System
11+
open System.IO
12+
open System.Xml.Linq
13+
14+
/// Options for using IISExpress
15+
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
16+
type IISExpressOptions =
17+
{ ToolPath : string }
18+
19+
/// IISExpress default parameters - tries to locate the iisexpress.exe
20+
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
21+
let IISExpressDefaults =
22+
{ ToolPath =
23+
let root =
24+
if Environment.Is64BitOperatingSystem then
25+
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
26+
else Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
27+
28+
Path.Combine(root, "IIS Express", "iisexpress.exe") }
29+
30+
/// Create a IISExpress config file from a given template
31+
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
32+
let createConfigFile (name, siteId : int, templateFileName, path, hostName, port : int) =
33+
let xname s = XName.Get(s)
34+
let uniqueConfigFile = Path.Combine(Path.GetTempPath(), "iisexpress-" + Guid.NewGuid().ToString() + ".config")
35+
use template = File.OpenRead(templateFileName)
36+
let xml = XDocument.Load(template)
37+
let sitesElement = xml.Root.Element(xname "system.applicationHost").Element(xname "sites")
38+
let appElement =
39+
XElement
40+
(xname "site", XAttribute(xname "name", name), XAttribute(xname "id", siteId.ToString()),
41+
XAttribute(xname "serverAutoStart", "true"),
42+
43+
XElement
44+
(xname "application", XAttribute(xname "path", "/"),
45+
46+
XElement
47+
(xname "virtualDirectory", XAttribute(xname "path", "/"), XAttribute(xname "physicalPath", DirectoryInfo(path).FullName))),
48+
49+
XElement
50+
(xname "bindings",
51+
52+
XElement
53+
(xname "binding", XAttribute(xname "protocol", "http"),
54+
XAttribute(xname "bindingInformation", "*:" + port.ToString() + ":" + hostName)),
55+
56+
XElement
57+
(xname "binding", XAttribute(xname "protocol", "http"),
58+
XAttribute(xname "bindingInformation", "*:" + port.ToString() + ":*"))))
59+
sitesElement.Add(appElement)
60+
xml.Save(uniqueConfigFile)
61+
uniqueConfigFile
62+
63+
/// This task starts the given site in IISExpress with the given ConfigFile.
64+
/// ## Parameters
65+
///
66+
/// - `setParams` - Function used to overwrite the default parameters.
67+
/// - `configFileName` - The file name of the IISExpress configfile.
68+
/// - `siteId` - The id (in the config file) of the website to run.
69+
///
70+
/// ## Sample
71+
///
72+
/// HostWebsite (fun p -> { p with ToolPath = "iisexpress.exe" }) "configfile.config" 1
73+
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
74+
let HostWebsite setParams configFileName siteId =
75+
let parameters = setParams IISExpressDefaults
76+
77+
use __ = traceStartTaskUsing "StartWebSite" configFileName
78+
let args = sprintf "/config:\"%s\" /siteid:%d" configFileName siteId
79+
tracefn "Starting WebSite with %s %s" parameters.ToolPath args
80+
81+
let proc =
82+
ProcessStartInfo(FileName = parameters.ToolPath, Arguments = args, UseShellExecute = false)
83+
|> Process.Start
84+
85+
proc
86+
87+
let HostStaticWebsite setParams folder =
88+
// https://blogs.msdn.microsoft.com/rido/2015/09/30/serving-static-content-with-iisexpress/
89+
let parameters = setParams IISExpressDefaults
90+
91+
use __ = traceStartTaskUsing "StartWebSite" folder
92+
let args = sprintf @"/path:""%s\""" folder
93+
tracefn "Starting WebSite with %s %s" parameters.ToolPath args
94+
95+
let proc =
96+
ProcessStartInfo(FileName = parameters.ToolPath, Arguments = args, UseShellExecute = false)
97+
|> Process.Start
98+
99+
proc
100+
101+
/// Opens the given url in the browser
102+
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
103+
let OpenUrlInBrowser url = Process.Start(url:string) |> ignore
104+
105+
/// Opens the given website in the browser
106+
[<System.Obsolete("This API is obsolete. There is no alternative in FAKE 5 yet. You can help by porting this module.")>]
107+
let OpenWebsiteInBrowser hostName port = sprintf "http://%s:%d/" hostName port |> OpenUrlInBrowser

0 commit comments

Comments
 (0)