Skip to content

Commit c1970d8

Browse files
CopilotBornToBeRoot
andcommitted
Improve Directory.Build.props based on code review feedback
- Simplified target execution to only run BeforeCompile - Added fallback to Windows PowerShell for better compatibility - Added UTF8 encoding to generated file - Moved condition to target level for better readability Co-authored-by: BornToBeRoot <[email protected]>
1 parent 1c03713 commit c1970d8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Source/Directory.Build.props

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
<PropertyGroup>
33
<!-- Define the current year for dynamic copyright -->
44
<CurrentYear>$([System.DateTime]::Now.Year)</CurrentYear>
5+
<!-- Use pwsh if available, otherwise fall back to powershell -->
6+
<PowerShellExe Condition="'$(PowerShellExe)' == '' And Exists('/usr/bin/pwsh')">pwsh</PowerShellExe>
7+
<PowerShellExe Condition="'$(PowerShellExe)' == ''">powershell</PowerShellExe>
58
</PropertyGroup>
69

710
<!-- Target to generate GlobalAssemblyInfo.cs from template before build -->
8-
<Target Name="GenerateGlobalAssemblyInfo" BeforeTargets="BeforeBuild;CoreCompile">
11+
<Target Name="GenerateGlobalAssemblyInfo" BeforeTargets="BeforeCompile" Condition="Exists('$(MSBuildThisFileDirectory)GlobalAssemblyInfo.cs.template')">
912
<Message Text="Generating GlobalAssemblyInfo.cs with year: $(CurrentYear)" Importance="high" />
1013

1114
<!-- Use PowerShell to replace the token in the template file -->
12-
<Exec Command="pwsh -NoProfile -ExecutionPolicy Bypass -Command &quot;(Get-Content '$(MSBuildThisFileDirectory)GlobalAssemblyInfo.cs.template') -replace '\{CURRENT_YEAR\}', '$(CurrentYear)' | Set-Content '$(MSBuildThisFileDirectory)GlobalAssemblyInfo.cs'&quot;"
13-
Condition="Exists('$(MSBuildThisFileDirectory)GlobalAssemblyInfo.cs.template')" />
15+
<Exec Command="$(PowerShellExe) -NoProfile -ExecutionPolicy Bypass -Command &quot;(Get-Content '$(MSBuildThisFileDirectory)GlobalAssemblyInfo.cs.template') -replace '\{CURRENT_YEAR\}', '$(CurrentYear)' | Set-Content '$(MSBuildThisFileDirectory)GlobalAssemblyInfo.cs' -Encoding UTF8&quot;" />
1416
</Target>
1517
</Project>

0 commit comments

Comments
 (0)