Can I output a text file on build with build details in it?

We have an issue with organizing our builds. They get copied around and moved so much that it's hard to keep track of what is the newest.

I would like to output a simple text file to the build root (same level as exe) that contains info like the build date and time, platform, etc.

Is this possible from within Unity? Right now we have no automated build process (CI/CD).

edit: I found onPreprocessBuild() but unfortunately one of our main projects still uses Unity 5.3.6f1, so this will not work. Is there an alternative?

In Unity 5.3, there is the PostProcessBuildAttribute. "Add this attribute to a method to get a notification just after building the player." (Source: UnityEditor.Callbacks.PostProcessBuildAttribute documentation.)

Using that attribute, you should be able to set up something like:

[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
{
CreateBuildTimestampFile(pathToBuiltProject);
}

private static void CreateBuildTimestampFile(string pathToBuiltProject)
{
string directory = Path.GetDirectoryName(pathToBuiltProject);

string timestampFile = Path.Combine(directory, "timestamp.txt");

if (File.Exists(timestampFile))
{
File.Delete(timestampFile);
}

using (var streamWriter = File.CreateText(timestampFile))
{
var timestamp = System.DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
streamWriter.WriteLine(timestamp);
}
}


As a side note, you may find the Unity 5.3 Build Player Pipeline documentation page useful as well.

• Thanks for the response, but you seem to be missing a bracket or something? I assume an opening bracket on line 3. Or I'm even worse at C# than I thought. – JOATMON Apr 9 '18 at 14:25
• Oops sorry about that. I edited my answer. – sonny Apr 9 '18 at 17:13
• Thanks. When I put this in a class (MyBuildPostProcessor), it throws an error on var timestamp saying that var has an "Unknown Resolve Error". Ideas? – JOATMON Apr 9 '18 at 17:17
• Maybe it's a namespace issue with DateTime? Is using System; present at the top of your file? Or try changing the line to use string instead: string timestamp = System.DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);. (Note: I edited the answer to fix a typo on the next line, and to incorporate this comment into the answer.) – sonny Apr 9 '18 at 17:30
• That was it, thanks. I also see you fixed the timestamp typo. All is working now, thanks so much! – JOATMON Apr 9 '18 at 17:31