-1

Is there any kind of "build counter" or "build start date" property that is unique per solution build.

That is if you build a solution with multiple projects that property will be the same for each project in the solution. And the property changes the next time the solution is built

Context: I am wring some MSBuild "script" AKA xml. and by property mean a MSBuild "variable" that can be used in that script

Simon
  • 33,714
  • 21
  • 133
  • 202
  • There is a unique GUID embedded in each assembly which changes with every build, but it is not the same across all (or any!) assemblies in the solution. See http://blogs.msdn.com/b/ericlippert/archive/2012/05/31/past-performance-is-no-guarantee-of-future-results.aspx – Blorgbeard Sep 09 '13 at 03:17
  • However, you can get the timestamp of the build: See http://stackoverflow.com/questions/1600962/displaying-the-build-date – Blorgbeard Sep 09 '13 at 03:19
  • What is it, that you are trying to solve? – Christian.K Sep 09 '13 at 05:37
  • @Christian.K not going down that path here. feel free to ping me on twitter "SimonCropp" – Simon Sep 09 '13 at 07:28
  • @Blorgbeard just like the GUID, the timestamp is for the assembly, right? So it wouldn't be global for the solution. Neat trickery nonetheless. – stijn Sep 09 '13 at 07:38
  • @Simon what do you mean with 'property'? An msbuild property? Something you can put in te code and access it by the compiler? Also, are you building with msbuild or from within VS? – stijn Sep 09 '13 at 07:39
  • @Blorgbeard you should ask and answer your own question that contains those comments :) – Simon Sep 09 '13 at 08:00
  • if you need a property in your own script that changes everytime you run it, can't you just generate a guid and use it (independent of the solution built)? That's as simple as `$([System.Guid]::NewGuid().ToString().ToUpper())` – stijn Sep 09 '13 at 08:09
  • @stijn and where would I put that to be unique per solution build? – Simon Sep 09 '13 at 08:24
  • hard to tell since you don't show the workings of your script, but I'd say in your script (supposing it's used to build the solution). Or maybe in a before.solutionname.sln.targets (see http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild.aspx) – stijn Sep 09 '13 at 10:24
  • @stijn that approach doesnt seem to work from within visual studio – Simon Sep 09 '13 at 22:48

1 Answers1

1

You can inject your own properties into solution build. So you can create your own guid or timestamp in format you need. Just create file with the name before.[Your solution file name].sln.targets in the folder of your colution.

Here is sample content of this file:

<!--?xml version="1.0" encoding="utf-8"?-->
<Project toolsversion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <MyBuildGuid>$([System.Guid]::NewGuid())</MyBuildGuid>
    <MyBuildStartTimestamp>$([System.DateTime]::Now.ToString("yyyyMMdd-HHmmss"))</MyBuildStartTimestamp>
  </PropertyGroup>  
  <Target Name="PrintMyPropertiesdBeforeBuild" BeforeTargets="Build">   
    <Message Text="MyBuildGuid before build: $(MyBuildGuid)" Importance="high" />
    <Message Text="MyBuildStartTimestamp: $(MyBuildStartTimestamp)" Importance="High" />
  </Target>

  <Target Name="PrintMyPropertiesAfterBuild" AfterTargets="Build">
    <Message Text="MyBuildGuid after build $(MyBuildGuid)" Importance="high" />
    <Message Text="MyBuildStartTimestamp: $(MyBuildStartTimestamp)" Importance="High" />
  </Target>  
</Project>
Palo Misik
  • 741
  • 3
  • 7
  • @Simon This may not solve your problem but...the behavior of Visual Studio is to read solutions and projects once. So if you add to your solution or project with extra MSBuild files (or edit them), you have to reload the solution or project for Visual Studio to mix them into the build. – Tom Blodget Sep 10 '13 at 00:21