<Project>
  <Target Name="StampBuildDate" BeforeTargets="CoreCompile">
    <PropertyGroup>
      <_BuildTimestamp>$([System.DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss"))</_BuildTimestamp>
      <_BuildTimestampFile>$(IntermediateOutputPath)BuildTimestamp.g.cs</_BuildTimestampFile>
    </PropertyGroup>
    <WriteLinesToFile
      File="$(_BuildTimestampFile)"
      Lines="[assembly: System.Reflection.AssemblyMetadata(&quot;BuildDate&quot;, &quot;$(_BuildTimestamp)&quot;)]"
      Overwrite="true"
      WriteOnlyWhenDifferent="false" />
    <ItemGroup>
      <Compile Include="$(_BuildTimestampFile)" />
    </ItemGroup>
  </Target>
</Project>
