-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[build] Use GitInfo to Generate Version information. (#875)
Context: d16b1e5 Context: b7982e4 Our previous attempt to use the [`GitInfo`][0] [NuGet Package][1] to generate Version information in commit d16b1e5 did not go as planned. It turns out that old-style projects do NOT support the `$(GenerateAssemblyInfo)` MSBuild property. As such the version information is never generated. As a result when we built the Xamarin.Android version of `Java.Interop` it never includes version information, which results in errors such as: error CS1705: Assembly 'Xamarin.Forms.Platform.Android' with identity 'Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'Java.Interop, Version=0.1.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' which has a higher version than referenced assembly 'Java.Interop' with identity 'Java.Interop, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065' Additionally, we were generating the version data on EVERY build. It could be optimized by only generating the required data on the first build, or in this case the `make prepare` step. Introduce a system where a `Version.props` file gets generated during the `make prepare` step and then that file is imported into all the sub-projects. We also have a system to make sure that for legacy projects the `$(GenerateAssemblyInfo)` property actually works. [0]: https://github.com/devlooped/GitInfo [1]: https://www.nuget.org/packages/GitInfo/2.1.2
- Loading branch information
1 parent
f359e73
commit 3e6a623
Showing
17 changed files
with
146 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks/GenerateVersionFile.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using System; | ||
using System.IO; | ||
using System.Collections.Generic; | ||
|
||
|
||
namespace Java.Interop.BootstrapTasks | ||
{ | ||
public class GenerateVersionFile : Task | ||
{ | ||
public ITaskItem InputFile { get; set; } | ||
public ITaskItem OutputFile { get; set; } | ||
|
||
public ITaskItem [] Replacements { get; set; } | ||
public override bool Execute () | ||
{ | ||
string text = File.ReadAllText (InputFile.ItemSpec); | ||
foreach (var replacement in Replacements) | ||
{ | ||
text = text.Replace (replacement.ItemSpec, replacement.GetMetadata ("Replacement")); | ||
} | ||
File.WriteAllText (OutputFile.ItemSpec, text); | ||
return !Log.HasLoggedErrors; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by a tool. | ||
// Runtime Version:4.0.30319.42000 | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
using System; | ||
using System.Reflection; | ||
|
||
[assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft Corporation")] | ||
[assembly: System.Reflection.AssemblyConfigurationAttribute("@CONFIGURATION@")] | ||
[assembly: System.Reflection.AssemblyCopyrightAttribute("Microsoft Corporation")] | ||
[assembly: System.Reflection.AssemblyFileVersionAttribute("@VERSION@.0")] | ||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("@INFORMATIONALVERSION@")] | ||
[assembly: System.Reflection.AssemblyProductAttribute("@PRODUCT@")] | ||
[assembly: System.Reflection.AssemblyTitleAttribute("@TITLE@")] | ||
[assembly: System.Reflection.AssemblyVersionAttribute("@VERSION@.0")] | ||
|
||
// Generated by the MSBuild WriteCodeFragment class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<Version>@VERSION@</Version> | ||
<InformationalVersion>@VERSION@ git-rev-head:@COMMIT@ git-branch:@BRANCH@</InformationalVersion> | ||
<Company>Microsoft Corporation</Company> | ||
<Copyright>Microsoft Corporation</Copyright> | ||
</PropertyGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
|
||
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Java.Interop.BootstrapTasks.dll" | ||
TaskName="Java.Interop.BootstrapTasks.GenerateVersionFile" /> | ||
<PropertyGroup> | ||
<GitDefaultBranch>main</GitDefaultBranch> | ||
<GitThisAssembly>false</GitThisAssembly> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="GitInfo" Version="2.1.2" PrivateAssets="all" /> | ||
</ItemGroup> | ||
|
||
<Target Name="GenerateVersionInfo" | ||
AfterTargets="Build" | ||
DependsOnTargets="GitVersion" | ||
Condition="!Exists ('$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Version.props')"> | ||
<ItemGroup> | ||
<Replacements Include="@VERSION@" Replacement="$(GitSemVerMajor).$(GitSemVerMinor).$(GitSemVerPatch)"/> | ||
<Replacements Include="@COMMIT@" Replacement="$(GitCommit)"/> | ||
<Replacements Include="@BRANCH@" Replacement="$(GitBranch)"/> | ||
</ItemGroup> | ||
<GenerateVersionFile | ||
InputFile="$(MSBuildThisFileDirectory)Version.props.in" | ||
OutputFile="$(MSBuildThisFileDirectory)..\..\bin\Build$(Configuration)\Version.props" | ||
Replacements="@(Replacements)" | ||
/> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters