lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [2/2] lucenenet git commit: Added LuceneInformationalVersionAttribute to work around issues with reading AssemblyInformationalVersionAttribute on .NET Core.
Date Tue, 11 Apr 2017 14:03:21 GMT
Added LuceneInformationalVersionAttribute to work around issues with reading AssemblyInformationalVersionAttribute
on .NET Core.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/f88cf9a5
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/f88cf9a5
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/f88cf9a5

Branch: refs/heads/api-work
Commit: f88cf9a528d09c3af476a4b6880991c1ab5889ae
Parents: 18baf32
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Tue Apr 11 21:01:50 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Tue Apr 11 21:01:50 2017 +0700

----------------------------------------------------------------------
 runbuild.ps1                                    |  4 ++-
 src/CommonAssemblyInfo.cs                       |  2 ++
 src/Lucene.Net/Lucene.Net.csproj                |  1 +
 .../LuceneInformationalVersionAttribute.cs      | 19 +++++++++++++
 src/Lucene.Net/Util/Constants.cs                | 29 +++-----------------
 5 files changed, 29 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f88cf9a5/runbuild.ps1
----------------------------------------------------------------------
diff --git a/runbuild.ps1 b/runbuild.ps1
index bb8a5e3..ed610ae 100644
--- a/runbuild.ps1
+++ b/runbuild.ps1
@@ -159,7 +159,8 @@ param(
 	$AssemblyVersion = $Matches[0]
 	$AssemblyVersion = "$AssemblyVersion.0.0"
 
-  $asmInfo = "using System;
+  $asmInfo = "using Lucene.Net.Support;
+using System;
 using System.Reflection;
 
 [assembly: AssemblyProduct(""$product"")]
@@ -169,6 +170,7 @@ using System.Reflection;
 [assembly: AssemblyVersion(""$AssemblyVersion"")] 
 [assembly: AssemblyFileVersion(""$version"")]
 [assembly: AssemblyInformationalVersion(""$packageVersion"")]
+[assembly: LuceneInformationalVersion(""$packageVersion"")]
 "
 	$dir = [System.IO.Path]::GetDirectoryName($file)
 	Ensure-Directory-Exists $dir

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f88cf9a5/src/CommonAssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/src/CommonAssemblyInfo.cs b/src/CommonAssemblyInfo.cs
index a66e328..8d38f2f 100644
--- a/src/CommonAssemblyInfo.cs
+++ b/src/CommonAssemblyInfo.cs
@@ -1,4 +1,5 @@
 ´╗┐using System.Reflection;
+using Lucene.Net.Support;
 
 // IMPORTANT: This file is overwritten by the build.ps1 script during release.
 // If you need to change this information, be sure to change the script as well.
@@ -24,3 +25,4 @@
 [assembly: AssemblyVersion("4.0.0")] 
 [assembly: AssemblyFileVersion("4.8.0")]
 [assembly: AssemblyInformationalVersion("4.8.0")]
+[assembly: LuceneInformationalVersion("4.8.0")]

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f88cf9a5/src/Lucene.Net/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Lucene.Net.csproj b/src/Lucene.Net/Lucene.Net.csproj
index d28a1a8..affaf2d 100644
--- a/src/Lucene.Net/Lucene.Net.csproj
+++ b/src/Lucene.Net/Lucene.Net.csproj
@@ -659,6 +659,7 @@
     <Compile Include="Support\LinkedHashMap.cs" />
     <Compile Include="Support\ListExtensions.cs" />
     <Compile Include="Support\LongBuffer.cs" />
+    <Compile Include="Support\LuceneInformationalVersionAttribute.cs" />
     <Compile Include="Support\LurchTable.cs" />
     <Compile Include="Support\MathExtension.cs" />
     <Compile Include="Support\MemoryMappedFileByteBuffer.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f88cf9a5/src/Lucene.Net/Support/LuceneInformationalVersionAttribute.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Support/LuceneInformationalVersionAttribute.cs b/src/Lucene.Net/Support/LuceneInformationalVersionAttribute.cs
new file mode 100644
index 0000000..5429544
--- /dev/null
+++ b/src/Lucene.Net/Support/LuceneInformationalVersionAttribute.cs
@@ -0,0 +1,19 @@
+´╗┐using System;
+
+namespace Lucene.Net.Support
+{
+    /// <summary>
+    /// Attribute for assigning and reading InformationalVersion, since <see cref="System.Reflection.AssemblyInformationalVersionAttribute"/>

+    /// is optimized away during compilation and cannot be read from .NET Core.
+    /// </summary>
+    [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)]
+    public class LuceneInformationalVersionAttribute : Attribute
+    {
+        public LuceneInformationalVersionAttribute(string version)
+        {
+            this.Version = version;
+        }
+
+        public string Version { get; private set; }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f88cf9a5/src/Lucene.Net/Util/Constants.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net/Util/Constants.cs b/src/Lucene.Net/Util/Constants.cs
index 4be1dcf..1147483 100644
--- a/src/Lucene.Net/Util/Constants.cs
+++ b/src/Lucene.Net/Util/Constants.cs
@@ -1,3 +1,4 @@
+using Lucene.Net.Support;
 using System;
 using System.Linq;
 using System.Reflection;
@@ -113,31 +114,9 @@ namespace Lucene.Net.Util
 
             try
             {
-                // LUCENENET NOTE: Use the AssemblyFileVersion, since our AssemblyVersion
should 
-                // remain at the major version (4.0.0.0). We only increment AssemblyVersion

-                // during a major release because strong-naming means 
-                // incrementing this version makes it binary incompatible.
-                string versionString;
-#if NETSTANDARD
-                versionString = typeof(Constants).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
-#else
-                versionString = FileVersionInfo.GetVersionInfo(typeof(Constants).GetTypeInfo().Assembly.Location).FileVersion;
-#endif
-                // LUCENENET NOTE: Convert to a 4-segment version number (in case it isn't)
-                switch (versionString.Count(x => x == '.'))
-                {
-                    case 2:
-                        versionString += ".0";
-                        break;
-                    case 1:
-                        versionString += ".0.0";
-                        break;
-                    case 0:
-                        versionString += ".0.0.0";
-                        break;
-                }
-
-                LUCENE_VERSION = versionString;
+                // LUCENENET NOTE: Added custom LuceneInformationalVersionAttribute to work
around
+                // issues with reading the AssemblyInformationalVersion in .NET core.
+                LUCENE_VERSION = typeof(Constants).GetTypeInfo().Assembly.GetCustomAttribute<LuceneInformationalVersionAttribute>().Version;
             }
             catch (System.Security.SecurityException) //Ignore in medium trust.
             {


Mime
View raw message