From c0cfd24a7d0503e2bfb64c3f84860371cca4f616 Mon Sep 17 00:00:00 2001
From: Michael Mell <michael.mell@unibas.ch>
Date: Tue, 5 Mar 2024 13:35:38 +0100
Subject: [PATCH] Use Post-Build-Script.ps1 to reset changes to BuildDetails.cs

---
 ATxCommon/ATxCommon.csproj           |  3 +++
 ATxDiagnostics/ATxDiagnostics.csproj |  3 +++
 ATxService/ATxService.csproj         |  3 +--
 ATxTray/ATXTray.csproj               |  3 +--
 Scripts/Post-Build-Script.ps1        | 22 ++++++++++++++++++++++
 5 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 Scripts/Post-Build-Script.ps1

diff --git a/ATxCommon/ATxCommon.csproj b/ATxCommon/ATxCommon.csproj
index 356e5cc..1b951b8 100644
--- a/ATxCommon/ATxCommon.csproj
+++ b/ATxCommon/ATxCommon.csproj
@@ -68,6 +68,9 @@
   <PropertyGroup>
     <PreBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Prepare-Build.ps1 -SolutionDir $(SolutionDir) -ConfigurationName $(ConfigurationName)</PreBuildEvent>
   </PropertyGroup>
+  <PropertyGroup>
+    <PostBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Post-Build-Script.ps1 -SolutionDir $(SolutionDir)</PostBuildEvent>
+  </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
   <Target Name="BeforeBuild">
diff --git a/ATxDiagnostics/ATxDiagnostics.csproj b/ATxDiagnostics/ATxDiagnostics.csproj
index bab54c8..f55138d 100644
--- a/ATxDiagnostics/ATxDiagnostics.csproj
+++ b/ATxDiagnostics/ATxDiagnostics.csproj
@@ -69,4 +69,7 @@
   <PropertyGroup>
     <PreBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Prepare-Build.ps1 -SolutionDir $(SolutionDir) -ConfigurationName $(ConfigurationName)</PreBuildEvent>
   </PropertyGroup>
+  <PropertyGroup>
+    <PostBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Post-Build-Script.ps1 -SolutionDir $(SolutionDir)</PostBuildEvent>
+  </PropertyGroup>
 </Project>
\ No newline at end of file
diff --git a/ATxService/ATxService.csproj b/ATxService/ATxService.csproj
index 968226f..7f29069 100644
--- a/ATxService/ATxService.csproj
+++ b/ATxService/ATxService.csproj
@@ -171,8 +171,7 @@
     <PreBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Prepare-Build.ps1 -SolutionDir $(SolutionDir) -ConfigurationName $(ConfigurationName)</PreBuildEvent>
   </PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>
-    </PostBuildEvent>
+    <PostBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Post-Build-Script.ps1 -SolutionDir $(SolutionDir)</PostBuildEvent>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/ATxTray/ATXTray.csproj b/ATxTray/ATXTray.csproj
index f5ef4c7..ca6e187 100644
--- a/ATxTray/ATXTray.csproj
+++ b/ATxTray/ATXTray.csproj
@@ -116,8 +116,7 @@
     <PreBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Prepare-Build.ps1 -SolutionDir $(SolutionDir) -ConfigurationName $(ConfigurationName)</PreBuildEvent>
   </PropertyGroup>
   <PropertyGroup>
-    <PostBuildEvent>
-    </PostBuildEvent>
+    <PostBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)Scripts\Post-Build-Script.ps1 -SolutionDir $(SolutionDir)</PostBuildEvent>
   </PropertyGroup>
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
diff --git a/Scripts/Post-Build-Script.ps1 b/Scripts/Post-Build-Script.ps1
new file mode 100644
index 0000000..9b9d7d9
--- /dev/null
+++ b/Scripts/Post-Build-Script.ps1
@@ -0,0 +1,22 @@
+<#
+.DESCRIPTION
+This script is intended to be executed as a "post-build" command in Visual Studio.
+It reverts changes made to specific files during the build process, ensuring they
+remain consistent with their pre-build state.
+
+Currently, it targets the "BuildDetails.cs" file within the "ATxCommon"
+directory of the specified solution.
+#>
+
+[CmdletBinding(DefaultParameterSetName="build")]
+Param(
+    [Parameter(Mandatory=$True, ParameterSetName="build")]
+    [Parameter(Mandatory=$True, ParameterSetName="gentemplate")]
+    [string] $SolutionDir
+)
+
+try {
+    git checkout --  "$($SolutionDir)\ATxCommon\BuildDetails.cs"
+} catch {
+    Write-Error "Git checkout failed. Is Git installed? File was not reset: $($SolutionDir)\ATxCommon\BuildDetails.cs"
+}
-- 
GitLab