Skip to content

Instantly share code, notes, and snippets.

@Slesa
Created July 9, 2013 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Slesa/5956492 to your computer and use it in GitHub Desktop.
Save Slesa/5956492 to your computer and use it in GitHub Desktop.
Suggestion to support the MAGE tool in FAKE
type MageProcessor = MSIL | X86
type MageCall = NewApp | UpdateApp | Sign | Deploy | UpdateDeploy | SignDeploy
type MageTrustLevels = Internet | LocalIntranet | FullTrust
type MageParams =
{ ToolsPath : string
ProjectFiles : seq<string>
Name : string
IconPath : string
IconFile : string
Processor : MageProcessor
Version : string
Manifest : string
FromDirectory : string
ApplicationFile : string
TrustLevel : MageTrustLevels option
CertFile : string
Password : string option
IncludeProvider : bool option
Install : bool option
UseManifest : bool option
Publisher : string option
CodeBase : string option
ProviderURL : string option
SupportURL : string option}
let MageSerializeParams (action: MageCall) (mp : MageParams) =
let processorStr =
match mp.Processor with
| MSIL -> "msil"
| X86 -> "x86"
let processor = "-p " + processorStr
let name = if isNullOrEmpty mp.Name then "" else "-n \"" + mp.Name + "\""
let iconFile = if isNullOrEmpty mp.IconFile then "" else "-if \"" + mp.IconFile + "\""
let version = if isNullOrEmpty mp.Version then "" else "-v " + mp.Version
let fromDir = if isNullOrEmpty mp.FromDirectory then "" else "-fd " + mp.FromDirectory
let manifest = if isNullOrEmpty mp.Manifest then "" else "-appm " + mp.Manifest
let certFile = if isNullOrEmpty mp.CertFile then "" else "-cf " + mp.CertFile
let trustlevelStr =
match mp.TrustLevel with
| None -> ""
| Some (p) ->
match p with
| Internet -> "Internet"
| LocalIntranet -> "LocalIntranet"
| FullTrust -> "FullTrust"
let trustlevel = if isNullOrEmpty trustlevelStr then "" else "-tr " + trustlevelStr
let password =
match mp.Password with
| None -> ""
| Some (p) -> "-pwd " + p
let includeProvider =
match mp.IncludeProvider with
| None -> ""
| Some (p) -> if p then "-ip true" else "ip false"
let install =
match mp.Install with
| None -> ""
| Some (p) -> if p then "-i true" else "-i false"
let useManifest =
match mp.UseManifest with
| None -> ""
| Some (p) -> if p then "-um true" else "-um false"
let publisher =
match mp.Publisher with
| None -> ""
| Some (p) -> "-pub \"" + p + "\""
let codeBase =
match mp.CodeBase with
| None -> ""
| Some (p) -> "-appc \"" + p + "\""
let providerUrl =
match mp.ProviderURL with
| None -> ""
| Some (p) -> "-pu \"" + p + "\""
let supportUrl =
match mp.SupportURL with
| None -> ""
| Some (p) -> "-s \"" + p + "\""
let algorithm = "-a sha256RSA" // "sha1RSA"
let allParameters =
match action with
| NewApp -> [processor; name; iconFile; version; fromDir; trustlevel; algorithm]
| UpdateApp -> [processor; name; iconFile; version; fromDir; trustlevel; algorithm]
| Sign -> [certFile; password]
| Deploy -> [processor; name; version; manifest; includeProvider; install; useManifest; publisher; providerUrl; supportUrl; codeBase; trustlevel; algorithm]
| UpdateDeploy -> [processor; name; version; manifest; includeProvider; install; useManifest; publisher; providerUrl; supportUrl; codeBase; trustlevel; algorithm]
| SignDeploy -> [certFile; password]
allParameters
|> separated " "
let mageCall (action : MageCall) (mp : MageParams) =
let magePath = mp.ToolsPath @@ "mage.exe"
let call =
match action with
| NewApp -> "New Application -t \"" + mp.Manifest + "\""
| UpdateApp -> "Update \"" + mp.Manifest + "\""
| Sign -> "Sign " + mp.Manifest
| Deploy -> "New Deployment -t \"" + mp.ApplicationFile + "\""
| UpdateDeploy -> "Update \"" + mp.ApplicationFile + "\""
| SignDeploy -> "Sign \"" + mp.ApplicationFile + "\""
let args = "-" + call + " " + MageSerializeParams action mp
let result =
ExecProcess (fun info ->
info.FileName <- magePath
info.Arguments <- args) System.TimeSpan.MaxValue
if result <> 0 then failwithf "Error during mage call "
let MageCreateApp (mp : MageParams) =
mageCall NewApp mp
let MageUpdateApp (mp : MageParams) =
mageCall UpdateApp mp
let MageSignManifest (mp : MageParams) =
mageCall Sign mp
let MageDeployApp (mp : MageParams) =
mageCall Deploy mp
let MageUpdateDeploy (mp : MageParams) =
mageCall UpdateDeploy mp
let MageSignDeploy (mp : MageParams) =
mageCall SignDeploy mp
let MageRun (mp : MageParams) =
MageCreateApp mp
MageSignManifest mp
MageDeployApp mp
MageSignDeploy mp
// Example call
let binDir = @".\Binaries\"
let clickOnce = binDir @@ @"clickonce\"
let clickOnceX64Dir = clickOnce @@ @"x64\\"
let clickOnceX86Dir = clickOnce @@ @"x86\\"
let ClickOnceBuild platform buildDir applicationFile mp =
if Directory.Exists buildDir then
Log "Cleaning dir: " [buildDir]
let allFiles = System.IO.Directory.GetFiles (buildDir, "*.*")
DeleteFiles allFiles
mp.ProjectFiles
|> MSBuild buildDir "Build" (["Configuration","Release"; "Platform", platform; "ProductName", mp.Name])
|> Log "ClickOnce build Output: "
if Directory.Exists buildDir then
let xmlFiles = System.IO.Directory.GetFiles (buildDir, "*.xml")
DeleteFiles xmlFiles
if not (isNullOrEmpty mp.IconFile) then
CopyFile buildDir (mp.IconPath @@ mp.IconFile)
MageRun mp
Target "MyApp32ClickOnce" (fun _ ->
let projectPath = "MyApp.x86.App"
let projectFiles =
!+ (projectPath @@ "MyApp.x86.App.csproj")
|> Scan
let buildDir = clickonceX86Dir @@ version
let applicationFile = clickOnceX86Dir @@ "MyApp.x86.application"
let mp =
{ ToolsPath = toolsDir @@ "WinSDK"
ProjectFiles = projectFiles
Name = "MyApp.x86"
IconPath = originalPath
IconFile = "MyApp-Producticon.ico"
Processor = X86
Manifest = buildDir @@ "MyApp.x86.exe.manifest"
FromDirectory = buildDir
ApplicationFile = applicationFile
Version = version
TrustLevel = None
CertFile = (projectPath @@ "MyApp.WPF_TemporaryKey.pfx")
Password = None
IncludeProvider = None // Some(true)
Install = Some(true)
UseManifest = Some(true)
Publisher = Some("Slesa Solutions")
CodeBase = Some(version + "/MyApp.x86.exe.manifest")
ProviderURL = Some("http://clickonce.homepage.de/x86/MyApp.x86.application")
SupportURL = Some("http://www.homepage.de/de/products/my-application") }
ClickOnceBuild "x86" buildDir applicationFile mp
)
Target "MyApp64ClickOnce" (fun _ ->
let projectPath = "MyApp"
let projectFiles =
!+ (projectPath @@ "MyApp.csproj")
|> Scan
let buildDir = clickOnceX64Dir @@ version
let applicationFile = clickOnceX64Dir @@ "MyApp.application"
let mp =
{ ToolsPath = toolsDir @@ "WinSDK"
ProjectFiles = projectFiles
Name = "MyApp"
IconPath = projectPath
IconFile = "MyApp-Producticon.ico"
Processor = MSIL
Manifest = (buildDir @@ "MyApp.exe.manifest")
FromDirectory = buildDir
ApplicationFile = applicationFile
Version = version
TrustLevel = None
CertFile = (projectPath @@ "MyApp.WPF_TemporaryKey.pfx")
Password = None
IncludeProvider = None // Some(true)
Install = Some(true)
UseManifest = Some(true)
Publisher = Some("Slesa Solutions")
CodeBase = Some(version + "/MyApp.exe.manifest")
ProviderURL = Some("http://clickonce.homepage.de/x64/MyApp.application")
SupportURL = Some("http://www.homepage.de/de/products/my-application") }
ClickOnceBuild "Any CPU" buildDir applicationFile mp
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment