Pārlūkot izejas kodu

C#: add System.Memory dependency for net45 too (#6317)

* introduce GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY

* allow building net45 target on unix systems too

* add Span<> support on net45 as well
Jan Tattermusch 6 gadi atpakaļ
vecāks
revīzija
e2f5da65ee

+ 4 - 8
csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj

@@ -18,13 +18,9 @@
     <PackageReference Include="NUnitLite" Version="3.6.1" />
     <PackageReference Include="NUnitLite" Version="3.6.1" />
   </ItemGroup>
   </ItemGroup>
 
 
-  <!--
-    - Override target frameworks on non-Windows to just .NET Core
-    - Doing this conditionally in the initial PropertyGroup confuses
-    - Visual Studio.
-    -->
-  <PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
-    <TargetFrameworks>netcoreapp2.1</TargetFrameworks>
-  </PropertyGroup>
+  <!-- Needed for the net45 build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
+  </ItemGroup>
 
 
 </Project>
 </Project>

+ 4 - 8
csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj

@@ -18,14 +18,10 @@
     <PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
     <PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
   </ItemGroup>
   </ItemGroup>
 
 
-  <!--
-    - Override target frameworks on non-Windows to just .NET Core
-    - Doing this conditionally in the initial PropertyGroup confuses
-    - Visual Studio.
-    -->
-  <PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
-    <TargetFrameworks>netcoreapp2.1</TargetFrameworks>
-  </PropertyGroup>
+  <!-- Needed for the net45 build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
+  </ItemGroup>
 
 
   <ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="testprotos.pb" />
     <EmbeddedResource Include="testprotos.pb" />

+ 2 - 2
csharp/src/Google.Protobuf/ByteString.cs

@@ -110,7 +110,7 @@ namespace Google.Protobuf
             get { return Length == 0; }
             get { return Length == 0; }
         }
         }
 
 
-#if NETSTANDARD2_0
+#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY
         /// <summary>
         /// <summary>
         /// Provides read-only access to the data of this <see cref="ByteString"/>.
         /// Provides read-only access to the data of this <see cref="ByteString"/>.
         /// No data is copied so this is the most efficient way of accessing.
         /// No data is copied so this is the most efficient way of accessing.
@@ -218,7 +218,7 @@ namespace Google.Protobuf
             return new ByteString(portion);
             return new ByteString(portion);
         }
         }
 
 
-#if NETSTANDARD2_0
+#if GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY
         /// <summary>
         /// <summary>
         /// Constructs a <see cref="ByteString" /> from a read only span. The contents
         /// Constructs a <see cref="ByteString" /> from a read only span. The contents
         /// are copied, so further modifications to the span will not
         /// are copied, so further modifications to the span will not

+ 8 - 8
csharp/src/Google.Protobuf/Google.Protobuf.csproj

@@ -22,16 +22,16 @@
     <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
     <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
   </PropertyGroup>
   </PropertyGroup>
 
 
-  <!--
-    - Override target frameworks on non-Windows to just .NET Core
-    - Doing this conditionally in the initial PropertyGroup confuses
-    - Visual Studio.
-    -->
-  <PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
-    <TargetFrameworks>netstandard1.0;netstandard2.0</TargetFrameworks>
+  <PropertyGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard2.0' ">
+    <DefineConstants>$(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY</DefineConstants>
   </PropertyGroup>
   </PropertyGroup>
 
 
-  <ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
+  <!-- Needed for the net45 build to work on Unix. See https://github.com/dotnet/designs/pull/33 -->
+  <ItemGroup>
+    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0-preview.2" PrivateAssets="All" />
+  </ItemGroup>
+
+  <ItemGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard2.0' ">
     <PackageReference Include="System.Memory" Version="4.5.2"/>
     <PackageReference Include="System.Memory" Version="4.5.2"/>
   </ItemGroup>
   </ItemGroup>