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
pull/6622/head
Jan Tattermusch 6 years ago committed by Jie Luo
parent 94cbf009e9
commit e2f5da65ee
  1. 12
      csharp/compatibility_tests/v3.0.0/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj
  2. 12
      csharp/src/Google.Protobuf.Test/Google.Protobuf.Test.csproj
  3. 4
      csharp/src/Google.Protobuf/ByteString.cs
  4. 16
      csharp/src/Google.Protobuf/Google.Protobuf.csproj

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

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

@ -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

@ -22,16 +22,16 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> <AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup> </PropertyGroup>
<!-- <PropertyGroup Condition=" '$(TargetFramework)' == 'net45' or '$(TargetFramework)' == 'netstandard2.0' ">
- Override target frameworks on non-Windows to just .NET Core <DefineConstants>$(DefineConstants);GOOGLE_PROTOBUF_SUPPORT_SYSTEM_MEMORY</DefineConstants>
- Doing this conditionally in the initial PropertyGroup confuses
- Visual Studio.
-->
<PropertyGroup Condition="'$(OS)' != 'Windows_NT'">
<TargetFrameworks>netstandard1.0;netstandard2.0</TargetFrameworks>
</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>

Loading…
Cancel
Save