Generate host and build info and store them in .props files

This commit is contained in:
Justin Goshi 2017-02-07 15:45:19 -08:00
parent da15d5435f
commit 83b46ebc17
5 changed files with 81 additions and 2 deletions

View file

@ -0,0 +1,39 @@
<Project ToolsVersion="15.0">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.tasks))\dir.tasks" />
<Target Name="WriteBuildInfoProps"
Condition=" !Exists('$(BuildInfoProps)') ">
<GetCommitHash RepoRoot="$(RepoRoot)">
<Output TaskParameter="CommitHash" PropertyName="CommitHash" />
</GetCommitHash>
<GenerateBuildVersionInfo RepoRoot="$(RepoRoot)"
VersionMajor="$(VersionMajor)"
VersionMinor="$(VersionMinor)"
VersionPatch="$(VersionPatch)"
ReleaseSuffix="$(ReleaseSuffix)">
<Output TaskParameter="CommitCount" PropertyName="CommitCount" />
<Output TaskParameter="MsiVersion" PropertyName="MsiVersion" />
<Output TaskParameter="VersionBadgeMoniker" PropertyName="VersionBadgeMoniker" />
</GenerateBuildVersionInfo>
<PropertyGroup>
<BuildInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
&lt;BuildCommitHash&gt;$(CommitHash)&lt;/BuildCommitHash&gt;
&lt;BuildCommitCount&gt;$(CommitCount)&lt;/BuildCommitCount&gt;
&lt;BuildMsiVersion&gt;$(MsiVersion)&lt;/BuildMsiVersion&gt;
&lt;BuildVersionBadgeMoniker&gt;$(VersionBadgeMoniker)&lt;/BuildVersionBadgeMoniker&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</BuildInfoPropsContent>
</PropertyGroup>
<MakeDir Directories="$(RepoRoot)/obj"/>
<WriteLinesToFile File="$(BuildInfoProps)"
Lines="$(BuildInfoPropsContent)" />
</Target>
</Project>

View file

@ -0,0 +1,30 @@
<Project ToolsVersion="15.0">
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.tasks))\dir.tasks" />
<Target Name="WriteHostInfoProps"
Condition=" !Exists('$(HostInfoProps)') ">
<GetCurrentRuntimeInformation>
<Output TaskParameter="Rid" PropertyName="Rid" />
<Output TaskParameter="Architecture" PropertyName="Architecture" />
<Output TaskParameter="OSName" PropertyName="OSName" />
</GetCurrentRuntimeInformation>
<PropertyGroup>
<HostInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
&lt;HostRid&gt;$(Rid)&lt;/HostRid&gt;
&lt;HostArchitecture&gt;$(Architecture)&lt;/HostArchitecture&gt;
&lt;HostOSName&gt;$(OSName)&lt;/HostOSName&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</HostInfoPropsContent>
</PropertyGroup>
<MakeDir Directories="$(RepoRoot)/obj"/>
<WriteLinesToFile File="$(HostInfoProps)"
Lines="$(HostInfoPropsContent)" />
</Target>
</Project>

View file

@ -1,10 +1,17 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Condition=" Exists('obj/Microsoft.DotNet.Cli.BuildInfo.props') "
Project="obj/Microsoft.DotNet.Cli.BuildInfo.props" />
<Import Condition=" Exists('obj/Microsoft.DotNet.Cli.HostInfo.props') "
Project="obj/Microsoft.DotNet.Cli.HostInfo.props" />
<Import Project="build/Microsoft.DotNet.Cli.DependencyVersions.props" />
<!-- NuGet Information -->
<PropertyGroup>
<RepoRoot>$(MSBuildThisFileDirectory)</RepoRoot>
<BuildInfoProps>$(RepoRoot)/obj/BuildInfo.props</BuildInfoProps>
<HostInfoProps>$(RepoRoot)/obj/HostInfo.props</HostInfoProps>
<NuGetPackagesDir>$(NUGET_PACKAGES)</NuGetPackagesDir>
<NuGetPackagesDir Condition=" '$(NuGetPackagesDir)' == '' ">$(RepoRoot)/.nuget/packages</NuGetPackagesDir>
@ -21,6 +28,5 @@
<CliVersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)-$(ReleaseSuffix)</CliVersionPrefix>
<CliTargetFramework>netcoreapp2.0</CliTargetFramework>
</PropertyGroup>
</Project>

View file

@ -114,6 +114,8 @@ if ($NoBuild)
}
else
{
dotnet msbuild build\Microsoft.DotNet.Cli.BuildInfo.targets /t:WriteBuildInfoProps
dotnet msbuild build\Microsoft.DotNet.Cli.HostInfo.targets /t:WriteHostInfoProps
dotnet msbuild build.proj /m /v:diag /p:Architecture=$Architecture $ExtraParameters
if($LASTEXITCODE -ne 0) { throw "Failed to build" }
}

View file

@ -179,6 +179,8 @@ export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1
echo "${args[@]}"
if [ $BUILD -eq 1 ]; then
dotnet msbuild build/Microsoft.DotNet.Cli.BuildInfo.targets /t:WriteBuildInfoProps
dotnet msbuild build/Microsoft.DotNet.Cli.HostInfo.targets /t:WriteHostInfoProps
dotnet msbuild build.proj /m /v:diag /p:Architecture=$ARCHITECTURE "${args[@]}"
else
echo "Not building due to --nobuild"