You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2022/01/25 21:32:53 UTC

[lucenenet] 01/02: lucene-cli + tests: added multi-targets for net6.0, net5.0, and netcoreapp3.1

This is an automated email from the ASF dual-hosted git repository.

nightowl888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/lucenenet.git

commit 79c2729c74a896f226418a66306f42a1fcee2498
Author: Shad Storhaug <sh...@shadstorhaug.com>
AuthorDate: Tue Jan 25 20:03:40 2022 +0700

    lucene-cli + tests: added multi-targets for net6.0, net5.0, and netcoreapp3.1
---
 .../publish-test-results-for-test-projects.yml     | 22 +++++++++++++++++-
 README.md                                          |  4 ++--
 src/Lucene.Net/readme-nuget.md                     |  4 ++--
 .../tools/Lucene.Net.Tests.Cli/InstallationTest.cs | 11 ++++++++-
 .../Lucene.Net.Tests.Cli.csproj                    | 27 +++++++++++++---------
 src/dotnet/tools/lucene-cli/docs/index.md          |  2 +-
 src/dotnet/tools/lucene-cli/lucene-cli.csproj      |  7 +++---
 7 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/.build/azure-templates/publish-test-results-for-test-projects.yml b/.build/azure-templates/publish-test-results-for-test-projects.yml
index 98a19aa..2f54790 100644
--- a/.build/azure-templates/publish-test-results-for-test-projects.yml
+++ b/.build/azure-templates/publish-test-results-for-test-projects.yml
@@ -81,7 +81,7 @@ steps:
     testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
     testResultsFileName: '${{ parameters.testResultsFileName }}'
 
-# Special case: Only supports net6.0
+# Special case: Only supports net6.0, net5.0, and netcoreapp3.1
 - template: publish-test-results.yml
   parameters:
     testProjectName: 'Lucene.Net.Tests.Cli'
@@ -92,6 +92,26 @@ steps:
     testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
     testResultsFileName: '${{ parameters.testResultsFileName }}'
 
+- template: publish-test-results.yml
+  parameters:
+    testProjectName: 'Lucene.Net.Tests.Cli'
+    framework: 'net5.0' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
+    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
+    osName: '${{ parameters.osName }}'
+    testResultsFormat: '${{ parameters.testResultsFormat }}'
+    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
+    testResultsFileName: '${{ parameters.testResultsFileName }}'
+
+- template: publish-test-results.yml
+  parameters:
+    testProjectName: 'Lucene.Net.Tests.Cli'
+    framework: 'netcoreapp3.1' # Since condtions are not supported for templates, we check for the file existence within publish-test-results.yml
+    vsTestPlatform: '${{ parameters.vsTestPlatform }}'
+    osName: '${{ parameters.osName }}'
+    testResultsFormat: '${{ parameters.testResultsFormat }}'
+    testResultsArtifactName: '${{ parameters.testResultsArtifactName }}'
+    testResultsFileName: '${{ parameters.testResultsFileName }}'
+
 # Special case: Only supports net48
 - template: publish-test-results.yml
   parameters:
diff --git a/README.md b/README.md
index 7590aca..b46763a 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Welcome to Apache Lucene.NET 
+# Welcome to Apache Lucene.NET 
 
 [![Nuget](https://img.shields.io/nuget/dt/Lucene.Net)](https://www.nuget.org/packages/Lucene.Net)
 [![Azure DevOps builds (master)](https://img.shields.io/azure-devops/build/lucene-net/6ba240c9-9598-47e7-a793-0ed8a4ba2f8b/3/master)](https://dev.azure.com/lucene-net/Lucene.NET/_build?definitionId=3&_a=summary)
@@ -125,7 +125,7 @@ There are several demos implemented as simple console applications that can be c
 
 There is also a dotnet command line tool available on NuGet. It contains all of the demos as well as tools maintaining your Lucene.NET index, featuring operations such as splitting, merging, listing segment info, fixing, deleting segments, upgrading, etc. Always be sure to back up your index before running any commands against it!
 
-- [Prerequisite: .NET Core 3.1.0 Runtime](https://www.microsoft.com/net/download/core#/runtime)
+- [Prerequisite: .NET Core 3.1 Runtime or Higher](https://dotnet.microsoft.com/en-us/download/dotnet)
 
 ```
 dotnet tool install lucene-cli -g --version 4.8.0-beta00015
diff --git a/src/Lucene.Net/readme-nuget.md b/src/Lucene.Net/readme-nuget.md
index b34010c..e3102b2 100644
--- a/src/Lucene.Net/readme-nuget.md
+++ b/src/Lucene.Net/readme-nuget.md
@@ -1,4 +1,4 @@
-Lucene.NET is a full-text search engine library capable of advanced text analysis, indexing, and searching. It can be used to easily add search capabilities to applications. Lucene.NET is a C# port of the popular Java Lucene search engine framework from The Apache Software Foundation, targeting the .NET platform.
+Lucene.NET is a full-text search engine library capable of advanced text analysis, indexing, and searching. It can be used to easily add search capabilities to applications. Lucene.NET is a C# port of the popular Java Lucene search engine framework from The Apache Software Foundation, targeting the .NET platform.
 
 ## Quick Start
 
@@ -133,7 +133,7 @@ There are several demos implemented as simple console applications that can be c
 
 There is also a dotnet command line tool available on NuGet. It contains all of the demos as well as tools maintaining your Lucene.NET index, featuring operations such as splitting, merging, listing segment info, fixing, deleting segments, upgrading, etc. Always be sure to back up your index before running any commands against it!
 
-- [Prerequisite: .NET 6.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
+- [Prerequisite: .NET Core 3.1 Runtime or Higher](https://dotnet.microsoft.com/en-us/download/dotnet)
 
 ```
 dotnet tool install lucene-cli -g --version 4.8.0-beta00015
diff --git a/src/dotnet/tools/Lucene.Net.Tests.Cli/InstallationTest.cs b/src/dotnet/tools/Lucene.Net.Tests.Cli/InstallationTest.cs
index 856f86f..9781963 100644
--- a/src/dotnet/tools/Lucene.Net.Tests.Cli/InstallationTest.cs
+++ b/src/dotnet/tools/Lucene.Net.Tests.Cli/InstallationTest.cs
@@ -70,12 +70,13 @@ namespace Lucene.Net.Tests.Cli
             }
 
             packageVersion = GetPackageVersion(packageFile.Name);
+            var targetFramework = GetTargetFramework();
 
             // Prepare our temp directory with a tool manifest so it can have local tools (we don't install globally to avoid conflicts with tools on dev machines).
             AssertCommandExitCode(ExitCode.Success, "dotnet", $"new tool-manifest --output \"{tempWork.FullName}\"");
 
             // Now install our tool and verify that the command succeeded.
-            AssertCommandExitCode(ExitCode.Success, "dotnet", $"tool install {LuceneCliToolName} --version {packageVersion} --add-source \"{packageFile.DirectoryName}\" --tool-path  \"{tempWork.FullName}\"");
+            AssertCommandExitCode(ExitCode.Success, "dotnet", $"tool install {LuceneCliToolName} --version {packageVersion} --framework {targetFramework} --add-source \"{packageFile.DirectoryName}\" --tool-path  \"{tempWork.FullName}\"");
         }
 
         public override void AfterClass()
@@ -119,6 +120,14 @@ namespace Lucene.Net.Tests.Cli
             return packageFile.Replace($"{LuceneCliToolName}.", string.Empty, StringComparison.Ordinal).Replace(".nupkg", string.Empty, StringComparison.Ordinal);
         }
 
+        private string GetTargetFramework()
+        {
+            var targetFrameworkAttribute = GetType().Assembly.GetAttributes<System.Reflection.AssemblyMetadataAttribute>(inherit: false).Where(a => a.Key == "TargetFramework").FirstOrDefault();
+            if (targetFrameworkAttribute is null)
+                Assert.Fail("TargetFramework metadata not found in this assembly.");
+            return targetFrameworkAttribute.Value;
+        }
+
         private string AppendCommandOutput(string message, string stdOut, string stdErr, int exitCode)
         {
             return $"{message}\n\nStdOut:\n{stdOut}\n\nStdErr:\n{stdErr}\n\nExit Code:\n{exitCode}";
diff --git a/src/dotnet/tools/Lucene.Net.Tests.Cli/Lucene.Net.Tests.Cli.csproj b/src/dotnet/tools/Lucene.Net.Tests.Cli/Lucene.Net.Tests.Cli.csproj
index dfd8068..f4940da 100644
--- a/src/dotnet/tools/Lucene.Net.Tests.Cli/Lucene.Net.Tests.Cli.csproj
+++ b/src/dotnet/tools/Lucene.Net.Tests.Cli/Lucene.Net.Tests.Cli.csproj
@@ -21,13 +21,17 @@
 -->  
 <Project Sdk="Microsoft.NET.Sdk">
 
+  <Import Project="$(SolutionDir)TestTargetFramework.props" />
+
   <PropertyGroup>
-    <TargetFramework>net6.0</TargetFramework>
+    <!-- Allow specific target framework to flow in from TestTargetFrameworks.props -->
+    <TargetFrameworks Condition=" '$(TargetFramework)' == '' ">net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
+    <!-- If .NET Frameowrk is specified, just target the latest version -->
+    <TargetFramework Condition=" $(TargetFramework.StartsWith('net4')) ">net6.0</TargetFramework>
     <AssemblyTitle>Lucene.Net.Tests.Cli</AssemblyTitle>
 
-    <IsPublishable>false</IsPublishable>
-    <IsPublishable Condition=" '$(TargetFramework)' == 'net6.0' ">true</IsPublishable>
-    <IsTestProject>true</IsTestProject>
+    <IsPublishable Condition="$(TargetFramework.StartsWith('net4'))">false</IsPublishable>
+    <IsTestProject Condition="$(TargetFramework.StartsWith('net4'))">false</IsTestProject>
   </PropertyGroup>
 
   <ItemGroup>
@@ -43,13 +47,14 @@
     <ProjectReference Include="..\..\..\Lucene.Net.TestFramework\Lucene.Net.TestFramework.csproj" />
   </ItemGroup>
 
-  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' ">
-    <PackageReference Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsConfigurationPackageVersion)" />
-    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="$(MicrosoftExtensionsConfigurationEnvironmentVariablesPackageVersion)" />
-    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="$(MicrosoftExtensionsConfigurationJsonPackageVersion)" />
-    <PackageReference Include="Microsoft.Extensions.Configuration.Xml" Version="$(MicrosoftExtensionsConfigurationXmlPackageVersion)" />
-  </ItemGroup>
-
   <Import Project="$(SolutionDir).build/TestReferences.Common.targets" />
 
+  <ItemGroup>
+    <!-- Add the target framework as metadata so our assembly knows which target it is testing -->
+    <AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute">
+      <_Parameter1>TargetFramework</_Parameter1>
+      <_Parameter2>$(TargetFramework)</_Parameter2>
+    </AssemblyAttribute>
+  </ItemGroup>
+
 </Project>
diff --git a/src/dotnet/tools/lucene-cli/docs/index.md b/src/dotnet/tools/lucene-cli/docs/index.md
index 7ed4283..1d6ff89 100644
--- a/src/dotnet/tools/lucene-cli/docs/index.md
+++ b/src/dotnet/tools/lucene-cli/docs/index.md
@@ -4,7 +4,7 @@ The Lucene.NET command line interface (CLI) is a new cross-platform toolchain wi
 
 ## Prerequisites
 
-- [.NET 6.0 Runtime](https://dotnet.microsoft.com/en-us/download/dotnet/6.0)
+- [.NET Core 3.1 Runtime or Higher](https://dotnet.microsoft.com/en-us/download/dotnet)
 
 ## Installation
 
diff --git a/src/dotnet/tools/lucene-cli/lucene-cli.csproj b/src/dotnet/tools/lucene-cli/lucene-cli.csproj
index 04bc6ad..aa3117f 100644
--- a/src/dotnet/tools/lucene-cli/lucene-cli.csproj
+++ b/src/dotnet/tools/lucene-cli/lucene-cli.csproj
@@ -24,9 +24,10 @@
   <Import Project="$(SolutionDir).build/nuget.props" />
 
   <PropertyGroup>
-    <TargetFramework>net6.0</TargetFramework>
+    <TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
 
-    <IsPublishable Condition=" '$(TargetFramework)' == 'net6.0' ">true</IsPublishable>
+    <IsPublishable>true</IsPublishable>
+    <IsPublishable Condition="$(TargetFramework.StartsWith('net4'))">false</IsPublishable>
     <PackAsTool>true</PackAsTool>
     <ToolCommandName>lucene</ToolCommandName>
     
@@ -45,7 +46,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <None Include="docs\index.md" Pack="true" PackagePath="\readme.md"/>
+    <None Include="docs\index.md" Pack="true" PackagePath="\readme.md" />
     <None Update="appsettings.json">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </None>