diff options
author | 2018-10-11 13:12:01 -0700 | |
---|---|---|
committer | 2018-10-14 04:24:52 -0700 | |
commit | ccacf24fb077e9de1f1bfb3af9ad33fb5de71870 (patch) | |
tree | 2f99cf1a87791ffa922347afdcb00c6bf54b69a9 /src/csharp/Grpc.Tools.Tests | |
parent | 716b5577fc7c744bb85730d134366f17f71ea00e (diff) |
Fix dotnet/Mono build and testing under Linux
Diffstat (limited to 'src/csharp/Grpc.Tools.Tests')
-rw-r--r-- | src/csharp/Grpc.Tools.Tests/Grpc.Tools.Tests.csproj | 49 | ||||
-rw-r--r-- | src/csharp/Grpc.Tools.Tests/NUnitMain.cs | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs | 3 |
3 files changed, 44 insertions, 10 deletions
diff --git a/src/csharp/Grpc.Tools.Tests/Grpc.Tools.Tests.csproj b/src/csharp/Grpc.Tools.Tests/Grpc.Tools.Tests.csproj index ab14f32afd..70c0474047 100644 --- a/src/csharp/Grpc.Tools.Tests/Grpc.Tools.Tests.csproj +++ b/src/csharp/Grpc.Tools.Tests/Grpc.Tools.Tests.csproj @@ -3,7 +3,7 @@ <Import Project="..\Grpc.Core\Version.csproj.include" /> <PropertyGroup> - <TargetFrameworks>net45;netcoreapp1.0</TargetFrameworks> + <TargetFrameworks>net45;netcoreapp1.0;netcoreapp2.1</TargetFrameworks> <OutputType>Exe</OutputType> </PropertyGroup> @@ -14,8 +14,8 @@ and may not compile Grpc.Core/Version.cs, as that file references constants in Grpc.Core.dll. TODO(kkm): Refactor imports. --> - <PropertyGroup Condition="'$(OS)' != 'Windows_NT'"> - <!-- Workaround for https://github.com/dotnet/sdk/issues/335 --> + <PropertyGroup Condition=" '$(OS)' != 'Windows_NT' and '$(MSBuildRuntimeType)' == 'Core' "> + <!-- Use Mono reference assemblies in SDK build: https://github.com/dotnet/sdk/issues/335 --> <FrameworkPathOverride Condition="Exists('/usr/lib/mono/4.5-api')">/usr/lib/mono/4.5-api</FrameworkPathOverride> <FrameworkPathOverride Condition="Exists('/usr/local/lib/mono/4.5-api')">/usr/local/lib/mono/4.5-api</FrameworkPathOverride> <FrameworkPathOverride Condition="Exists('/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5-api')">/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5-api</FrameworkPathOverride> @@ -27,16 +27,47 @@ <ItemGroup> <PackageReference Include="Moq" Version="4.8.3" /> - <PackageReference Include="NUnit" Version="3.10.1" /> - <PackageReference Include="NUnitLite" Version="3.10.1" /> - </ItemGroup> - - <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' "> - <PackageReference Include="Microsoft.Build.Framework; Microsoft.Build.Utilities.Core" Version="15.6.85" /> + <PackageReference Include="NUnit; NUnitLite" Version="3.10.1" /> </ItemGroup> <ItemGroup Condition=" '$(TargetFramework)' == 'net45' "> <Reference Include="Microsoft.Build.Framework; Microsoft.Build.Utilities.v4.0" /> </ItemGroup> + <ItemGroup Condition=" '$(TargetFramework)' != 'net45' "> + <PackageReference Include="Microsoft.Build.Framework; Microsoft.Build.Utilities.Core" Version="15.6.*" /> + </ItemGroup> + + <!-- Groups below is a hack to allow the test to run under Mono Framework build. + ========================================================================== --> + + <!-- Mono unfortunately comes with broken Microsoft.Build.* assemblies installed in + the GAC, but fortunately searches for runtime assemblies in a different order + than Windows CLR host: the GAC assemblies have the lowest search priority, (see + https://www.mono-project.com/docs/advanced/assemblies-and-the-gac/), not the + highest as is in Windows (documented at + https://docs.microsoft.com/dotnet/framework/deployment/how-the-runtime-locates-assemblies). + To run the tests under Mono, we need correct assemblies in the same directory as + the test executable. Correct versions are in the MSBuild directory under Mono. --> + <ItemGroup Condition=" '$(TargetFramework)' == 'net45' and '$(OS)' != 'Windows_NT' "> + <None Include="$(_MSBuildAssemblyPath)/Microsoft.Build.Framework.dll; + $(_MSBuildAssemblyPath)/Microsoft.Build.Utilities.v4.0.dll; + $(_MSBuildAssemblyPath)/Microsoft.Build.Utilities.Core.dll" + CopyToOutputDirectory="Always" Visible="false" /> + </ItemGroup> + <PropertyGroup Condition=" '$(TargetFramework)' == 'net45' and '$(OS)' != 'Windows_NT' "> + <!-- The None items are included into assembly candidate resolution by default, and + we do not want that, as they are not valid as reference assemblies (the version of + Microsoft.Build.Utilities.v4.0 is a pure facade for Microsoft.Build.Utilities.Core, + and does not define any types at all). Exclude them from assembly resolution. See + https://github.com/Microsoft/msbuild/blob/50639058f/documentation/wiki/ResolveAssemblyReference.md --> + <AssemblySearchPaths>{HintPathFromItem};{TargetFrameworkDirectory};{RawFileName}</AssemblySearchPaths> + <!-- Locate Mono's copy of MSBuild assemblies for cross-build. --> + <_MSBuildAssemblyPath Condition=" '$(MSBuildRuntimeType)' == 'Core' " + >$(FrameworkPathOverride)/../msbuild/$(MSBuildToolsVersion)/bin</_MSBuildAssemblyPath> + <!-- Use Mono-provided patch for Mono build. --> + <_MSBuildAssemblyPath Condition=" '$(MSBuildRuntimeType)' != 'Core' " + >$(MSBuildToolsPath)</_MSBuildAssemblyPath> + </PropertyGroup> + </Project> diff --git a/src/csharp/Grpc.Tools.Tests/NUnitMain.cs b/src/csharp/Grpc.Tools.Tests/NUnitMain.cs index 5a8ae8cf87..5784cdeac2 100644 --- a/src/csharp/Grpc.Tools.Tests/NUnitMain.cs +++ b/src/csharp/Grpc.Tools.Tests/NUnitMain.cs @@ -22,7 +22,7 @@ using NUnitLite; namespace Grpc.Tools.Tests { static class NUnitMain { public static int Main(string[] args) => -#if NETCOREAPP1_0 +#if NETCOREAPP1_0 || NETCOREAPP1_1 new AutoRun(typeof(NUnitMain).GetTypeInfo().Assembly).Execute(args); #else new AutoRun().Execute(args); diff --git a/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs b/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs index c5d43f08d9..06376f8ef4 100644 --- a/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs +++ b/src/csharp/Grpc.Tools.Tests/ProtoCompileCommandLineGeneratorTest.cs @@ -16,6 +16,7 @@ #endregion +using System.IO; using Microsoft.Build.Framework; using Moq; using NUnit.Framework; @@ -152,6 +153,8 @@ namespace Grpc.Tools.Tests { [TestCase("C:\\" , "C:\\")] [TestCase("C:\\\\" , "C:\\")] public void DirectorySlashTrimmingCases(string given, string expect) { + if (Path.DirectorySeparatorChar == '/') + expect = expect.Replace('\\', '/'); _task.OutputDir = given; ExecuteExpectSuccess(); Assert.That(_task.LastResponseFile, |