From 994f9635ef77b60ec79797db2bc8ccc981362474 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Sat, 18 Dec 2021 01:29:26 +0100
Subject: [PATCH] Fix post build scripts to support moved F# executables

---
 .gitignore         |  1 +
 TweetDuck.csproj   | 10 +++-------
 bld/POST BUILD.bat | 12 ------------
 bld/POST BUILD.ps1 | 22 ++++++++++++++++++++++
 4 files changed, 26 insertions(+), 19 deletions(-)
 delete mode 100644 bld/POST BUILD.bat
 create mode 100644 bld/POST BUILD.ps1

diff --git a/.gitignore b/.gitignore
index bb7ef794..4fcdddf4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,6 +5,7 @@
 bld/*
 !bld/*.iss
 !bld/*.bat
+!bld/*.ps1
 !bld/Redist
 !bld/Resources
 
diff --git a/TweetDuck.csproj b/TweetDuck.csproj
index 5426a663..a6d9b539 100644
--- a/TweetDuck.csproj
+++ b/TweetDuck.csproj
@@ -405,15 +405,11 @@ rmdir "$(ProjectDir)bin\Release"
 rmdir "$(TargetDir)scripts" /S /Q
 rmdir "$(TargetDir)plugins" /S /Q
 
-IF EXIST "$(ProjectDir)bld\post_build.exe" (
-  "$(ProjectDir)bld\post_build.exe" "$(TargetDir)\" "$(ProjectDir)\" "$(ConfigurationName)"
-) ELSE (
-  "$(DevEnvDir)CommonExtensions\Microsoft\FSharp\fsi.exe" "$(ProjectDir)Resources\PostBuild.fsx" --exec --nologo -- "$(TargetDir)\" "$(ProjectDir)\" "$(ConfigurationName)"
-)
+"$(ProjectDir)bld\post_build.exe" "$(TargetDir)\" "$(ProjectDir)\" "$(ConfigurationName)"
 </PostBuildEvent>
   </PropertyGroup>
-  <Target Name="BeforeBuild" Condition="(!$([System.IO.File]::Exists(&quot;$(ProjectDir)\bld\post_build.exe&quot;)) OR ($([System.IO.File]::GetLastWriteTime(&quot;$(ProjectDir)\Resources\PostBuild.fsx&quot;).Ticks) &gt; $([System.IO.File]::GetLastWriteTime(&quot;$(ProjectDir)\bld\post_build.exe&quot;).Ticks)))">
-    <Exec Command="&quot;$(ProjectDir)bld\POST BUILD.bat&quot; &quot;$(DevEnvDir)CommonExtensions\Microsoft\FSharp\fsc.exe&quot;" WorkingDirectory="$(ProjectDir)bld\" IgnoreExitCode="true" />
+  <Target Name="BeforeBuild" Condition="(!$([System.IO.File]::Exists(&quot;$(ProjectDir)bld\post_build.exe&quot;)) OR ($([System.IO.File]::GetLastWriteTime(&quot;$(ProjectDir)Resources\PostBuild.fsx&quot;).Ticks) &gt; $([System.IO.File]::GetLastWriteTime(&quot;$(ProjectDir)bld\post_build.exe&quot;).Ticks)))">
+    <Exec Command="powershell -NoProfile -ExecutionPolicy Bypass -File &quot;$(ProjectDir)bld\POST BUILD.ps1&quot; &quot;$(DevEnvDir)\CommonExtensions\Microsoft\FSharp&quot;" WorkingDirectory="$(ProjectDir)bld\" IgnoreExitCode="true" />
   </Target>
   <Target Name="AfterBuild" Condition="$(ConfigurationName) == Release">
     <Exec Command="del &quot;$(TargetDir)*.pdb&quot;" />
diff --git a/bld/POST BUILD.bat b/bld/POST BUILD.bat
deleted file mode 100644
index 16089dfb..00000000
--- a/bld/POST BUILD.bat	
+++ /dev/null
@@ -1,12 +0,0 @@
-@ECHO OFF
-
-IF EXIST "post_build.exe" (
-  DEL "post_build.exe"
-)
-
-IF NOT EXIST %1 (
-  ECHO fsc.exe not found
-  EXIT 1
-)
-
-%1 --standalone --deterministic --preferreduilang:en-US --platform:x86 --target:exe --out:post_build.exe "%~dp0..\Resources\PostBuild.fsx"
diff --git a/bld/POST BUILD.ps1 b/bld/POST BUILD.ps1
new file mode 100644
index 00000000..575ed712
--- /dev/null
+++ b/bld/POST BUILD.ps1	
@@ -0,0 +1,22 @@
+if ([IO.File]::Exists("post_build.exe")) {
+  [IO.File]::Delete("post_build.exe");
+}
+
+$fs = $args[0];
+$fsc = "";
+
+if ([IO.File]::Exists("$fs\fsc.exe")) {
+  $fsc = "$fs\fsc.exe";
+}
+
+if ([IO.File]::Exists("$fs\Tools\fsc.exe")) {
+  $fsc = "$fs\Tools\fsc.exe";
+}
+
+if ($fsc -eq "") {
+  Write-Host "fsc.exe not found"
+  $Host.SetShouldExit(1);
+  exit
+}
+
+& $fsc --standalone --deterministic --preferreduilang:en-US --platform:x86 --target:exe --out:post_build.exe "$PSScriptRoot\..\Resources\PostBuild.fsx"