[Java.Interop] $(Version) depends on TargetFramework #952
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context: 2d5431f
Context: 88d6093
Context: #936
Context: https://github.com/jonpryor/java.interop/commits/jonp-registration-scope
Versioning is hard.
Way back in 3e6a623 we tried to use the
GitInfoNuGet package sothat all assemblies would have a version number which contained the
number of commits since
GitInfo.txtchanged.This turned out to have unanticipated breakage, and was largely
reverted in 2d5431f for "core" libs like
Java.Interop.dll, butretained for "utility" apps and libs like
generator.exe.This still presents a problem, though: the point to assembly
versioning is to prevent accidental breaking of referencing
assemblies. If we add a new member to
Java.Interop.dllbutfail to update the version, then that permits a scenario in which
an app/lib depends on the new member, but is built against a version
missing that member. This results in runtime exceptions.
The whole reason this hasn't been a problem so far is because
Java.Interop.dllhas barely changed in years. (Plus, most usageis hidden behind other layers and libs…)
However, I want this to change: #936 and
jonpryor/java.interop/jonp-registration-scope both add new public
API to
Java.Interop.dll, and there are other features andoptimizations we're considering that would also require API changes.
A policy of "no changes" isn't tenable.
Thus: allow
Java.Interop.dllbuilt for .NET 6 to have a different$(Version)than the one built for .NET Standard 2.0.Fixing this was unexpectedly problematic, as commit 88d6093:
Java.Interop.BootstrapTasks.dlldoesn't need to be versioned, butother assemblies do, and this change change meant that
VersionInfo.targetswas never used, which in turn meant that e.g.bin/BuildDebug/Version.propswas never created.This change also implicitly reverted all remaining 3e6a623
behavior; in commit 13def0e (one prior to 88d6093),
generator.exehad a version of 0.1.45.0. Starting with commit 88d6093,
generator.exehad version 1.0.0.0, which re-introduces the"baseline" scenario which first necessitated 3e6a623!
Re-think this process, while avoiding the circular dependency:
Java.Interop.BootstrapTasks.targetsnow generates aVersion.propsfile, re-introducing its existence.Version.propsnow contains four version values:$(JINetToolVersion): Version to use for "utility"assemblies which target .NET.
$(JINetCoreLibVersion): Version to use for "core library"assemblies which target .NET.
$(JIOldToolVersion): Version to use for "utility"assemblies which target .NET Standard/Framework/etc.
$(JIOldCoreLibVersion): Version to use for "core library"assemblies which target .NET Standard/Framework/etc.
The
$(JINet*)values derive their major, minor, and patchvalues from
GitInfo, while the$(JIOld*)values arebackward compatible (-ish).
Update/replace
VersionInfo.targetswith a_SetInformationalVersiontarget, which sets the$(InformationalVersion)MSBuild property based on the valueof
$(Version)and various other properties.Directory.Build.propsis updated to provide new$(JIUtilityVersion)and$(JICoreLibVersion)properties, whichare set based on the
$(TargetFramework)value.Set the default
$(Version)value to$(JIUtilityVersion)."Core library" assemblies must explicitly set
$(Version)intheir
.csprojto instead be$(JICoreLibVersion).The result is that for "core libraries" such as
Java.Interop.dll,when building for .NET Standard or MonoAndroid they will continue to
use version 0.1.0.0 (see also 2d5431f), while these assemblies will
use version 6.0.0.0 when built for .NET Core/6.
"Utility" assemblies such as
generator.exewill contain a versionnumber which changes based on when
GitInfo.txtwas last changed.When building for .NET Standard, they will use version
0.2.$(GitBaseVersionPatch).$(GitCommits), which differs from thepre-88d6093c pattern of
0.1.$(GitSemVerPatch).0, but as my currentsystem Xamarin.Android v12.1.99.117 install shows that
generator.exehas version 0.1.31.0, "rebasing" on 0.2.x feels easiest.
When utility assemblies are built for .NET, they will instead use the
values from
GitInfo.txt, e.g.6.0.0.$(GitCommits).Finally, always set
$(FileVersion)to:$(FileVersion)is used to set$(AssemblyFileVersionAttribute), which is not used forassembly binding, but is shown in the Windows File Properties
dialog, and can be used to (indirectly) determine which commit an
assembly was built from.