Reputation: 3098
Is there a property or another way in MSBuild that would hold the start time of a build?
I have explored my builds with the MSBuild structured viewer but found nothing.
Upvotes: 1
Views: 354
Reputation: 5801
First of all, project files (csproj
) are actually MSBuild files, so we can use MSBuild variables.
The problem is when we compile the entire solution (sln
), we don't have an MSBuild file to declare variables and change the default behavior of MSBuild Build
target.
So in the first step, we will need to create an MSBuild file for the sln
:
You can change this environment variable to generate the MSBuild file from the build process:
Set MSBuildEmitSolution=1
msbuild {yourSlnFile}.sln
The root folder now should contain a file with .sln.metaproj
, that you can compile the solution with him (msbuild {yourSlnFile}.sln.metaproj /t:Build
)
You can create your own MSBuild file for compile the solution with him, and he will be cleaner from the first option:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Text="$([System.DateTime]::Now.ToString(`yyyy.MMdd`))"></Message>
<MSBuild Projects="{yourSlnFile}.sln" Properties="Configuration=$(Configuration); Platform=$(Platform)" />
</Target>
</Project>
Now, in your custom MSBuild file to build the sln
, you can declare a tag in PropertyGroup
, and this tag will hold the DateTime
in your file:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<StartCommandTime>$([System.DateTime]::Now.ToString(`yyyy.MMdd`))</StartCommandTime>
</PropertyGroup>
<Target Name="Build">
<Message Text="$(StartCommandTime)"></Message>
<MSBuild Projects="{yourSlnFile}.sln" Properties="Configuration=$(Configuration); Platform=$(Platform)" />
<Message Text="$(StartCommandTime)"></Message>
</Target>
</Project>
Upvotes: 2