Skip to content

Instantly share code, notes, and snippets.

@cjaSource
Last active February 15, 2021 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cjaSource/fdc34444ab1ae6036604f0d750f59041 to your computer and use it in GitHub Desktop.
Save cjaSource/fdc34444ab1ae6036604f0d750f59041 to your computer and use it in GitHub Desktop.
Directory.Build.targets NETFramework
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
<UsingTask TaskName="LaunchTelemetry" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<BuildTimeToRegister ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System.Diagnostics" />
<Using Namespace="System.Runtime " />
<Code Type="Fragment" Language="cs">
<![CDATA[
try {
ProcessStartInfo sinfo = new ProcessStartInfo();
sinfo.CreateNoWindow = true;
sinfo.UseShellExecute = false;
sinfo.FileName = @"]]>$(SolutionDir)BuildScripts\tools\Cake\Cake.exe<![CDATA[";
string cakeFile = @"]]>$(SolutionDir)BuildScripts\vstelemetry.cake<![CDATA[";
string queryParams = " --buildtime=" + BuildTimeToRegister + " --project=]]>'$(ProjectName)'<![CDATA[";
sinfo.Arguments = " " + cakeFile + queryParams;
Process.Start(sinfo);
} catch(Exception) {
// Do not interfere with devs
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name="beforebuild" BeforeTargets="build" Condition="'$(BuildingSS_fcbat)' != 'true'">
<PropertyGroup>
<Time>$([System.DateTime]::Now)</Time>
</PropertyGroup>
</Target>
<Target Name="afterbuild" AfterTargets="build" Condition="'$(BuildingSS_fcbat)' != 'true'">
<PropertyGroup>
<BuildTime>$([System.DateTime]::Now.Subtract($([System.DateTime]::Parse($(Time)))).ToString())</BuildTime>
</PropertyGroup>
<LaunchTelemetry BuildTimeToRegister="'$(BuildTime)'" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment