Skip to content
Snippets Groups Projects
Commit c6312595 authored by Niko Ehrenfeuchter's avatar Niko Ehrenfeuchter :keyboard:
Browse files

Move pre-build event to an external PowerShell script.

Plus also check if the repository's commit state is dirty and report
accordingly.
parent 1ee6ae47
Branches
Tags
No related merge requests found
......@@ -152,7 +152,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>PowerShell -Command "$BCommit = '$(ProjectDir)\Resources\BuildCommit.txt' ; $BDate = '$(ProjectDir)\Resources\BuildDate.txt' ; if (-Not (Test-Path $BCommit)) { Write-Output 'UNKNOWN' &gt; $BCommit } ; Get-Date -Format 'yyyy-MM-dd HH:mm:ss' &gt; $BDate ; Get-Content $BDate"</PreBuildEvent>
<PreBuildEvent>PowerShell -NoProfile -ExecutionPolicy RemoteSigned $(SolutionDir)\Scripts\Prepare-Build.ps1 $(ProjectDir)</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>PowerShell -Command "Write-Host $(ConfigurationName)" &gt; $(ProjectDir)\Resources\BuildConfiguration.txt
......
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)][string] $ProjectDir
)
$oldpwd = pwd
cd $ProjectDir -ErrorAction Stop
try {
$CommitName = git describe --tags
$GitStatus = git status --porcelain
}
catch {
$CommitName = "commit unknown"
$GitStatus = "status unknown"
}
if ($GitStatus.Length -gt 0) {
Write-Output "NOTE: repository has uncommitted changes!"
$CommitName = "$($CommitName)-unclean"
}
$Date = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$BCommit = "$($ProjectDir)\Resources\BuildCommit.txt"
$BuildDate = "$($ProjectDir)\Resources\BuildDate.txt"
Write-Output $CommitName > $BCommit
Write-Output $Date > $BuildDate
Write-Output $Date
Write-Output $CommitName
cd $oldpwd
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment