|
27 | 27 |
|
28 | 28 | <Choose>
|
29 | 29 | <When Condition="'$(TargetFramework)' == 'netstandard1.4'">
|
| 30 | + <!-- |
| 31 | + .NET Standard 1.4 lacks the [Pure] attribute, the Rectangle primitive, |
| 32 | + the Span<T> and Memory<T> types, the Vector<T> primitive and related APIs, |
| 33 | + ValueTask and ValueTask<T>, the Parallel class and the Unsafe class. |
| 34 | + We also need to reference the System.Runtime.CompilerServices.Unsafe package directly, |
| 35 | + even though System.Memory references it already, as we need a more recent version than |
| 36 | + the one bundled with it. This is so that we can use the Unsafe.Unbox<T> method, |
| 37 | + which is used by the Box<T> type in the package. |
| 38 | + --> |
30 | 39 | <ItemGroup>
|
31 |
| - <!-- .NET Standard 1.4 lacks the [Pure] attribute, the Rectangle primitive, |
32 |
| - the Span<T> and Memory<T> types, the Vector<T> primitive and related APIs, |
33 |
| - ValueTask and ValueTask<T>, the Parallel class and the Unsafe class. |
34 |
| - We also need to reference the System.Runtime.CompilerServices.Unsafe package directly, |
35 |
| - even though System.Memory references it already, as we need a more recent version than |
36 |
| - the one bundled with it. This is so that we can use the Unsafe.Unbox<T> method, |
37 |
| - which is used by the Box<T> type in the package. --> |
38 | 40 | <PackageReference Include="System.Diagnostics.Contracts" Version="4.3.0" />
|
39 | 41 | <PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
|
40 | 42 | <PackageReference Include="System.Memory" Version="4.5.4" />
|
|
46 | 48 | </When>
|
47 | 49 |
|
48 | 50 | <When Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
| 51 | + <!-- .NET Standard 2.0 doesn't have the Span<T>, HashCode and ValueTask types --> |
49 | 52 | <ItemGroup>
|
50 |
| - <!-- .NET Standard 2.0 doesn't have the Span<T>, HashCode and ValueTask types --> |
51 | 53 | <PackageReference Include="Microsoft.Bcl.HashCode" Version="1.1.0" />
|
52 | 54 | <PackageReference Include="System.Memory" Version="4.5.4" />
|
53 | 55 | <PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
|
|
56 | 58 | </When>
|
57 | 59 |
|
58 | 60 | <When Condition="'$(TargetFramework)' == 'netstandard2.1'">
|
| 61 | + <!-- .NET Standard 2.1 doesn't have the Unsafe type --> |
59 | 62 | <ItemGroup>
|
60 |
| - <!-- .NET Standard 2.1 doesn't have the Unsafe type --> |
61 | 63 | <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
|
62 | 64 | </ItemGroup>
|
63 | 65 | <PropertyGroup>
|
64 |
| - <!-- NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET Core 3.1. |
65 |
| - This is needed because .NET Core 3.1 will be a separate package than .NET Standard 2.1. --> |
| 66 | + <!-- |
| 67 | + NETSTANDARD2_1_OR_GREATER: includes both .NET Standard 2.1 and .NET Core 3.1. |
| 68 | + This is needed because .NET Core 3.1 will be a separate package than .NET Standard 2.1. |
66 | 69 |
|
67 |
| - <!-- SPAN_RUNTIME_SUPPORT: define a constant to indicate runtimes with runtime support for |
68 |
| - the fast Span<T> type, as well as some overloads with Span<T> parameters (eg. Stream.Write). |
69 |
| - In particular, these are runtimes which are able to create Span<T> instances from just |
70 |
| - a managed reference, which can be used to slice arbitrary objects not technically supported. |
71 |
| - This API (MemoryMarshal.CreateSpan) is not part of .NET Standard 2.0, but it is still |
72 |
| - available on .NET Core 2.1. So by using this constant, we can make sure to expose those |
73 |
| - APIs relying on that method on all target frameworks that are able to support them. --> |
| 70 | + SPAN_RUNTIME_SUPPORT: define a constant to indicate runtimes with runtime support for |
| 71 | + the fast Span<T> type, as well as some overloads with Span<T> parameters (eg. Stream.Write). |
| 72 | + In particular, these are runtimes which are able to create Span<T> instances from just |
| 73 | + a managed reference, which can be used to slice arbitrary objects not technically supported. |
| 74 | + This API (MemoryMarshal.CreateSpan) is not part of .NET Standard 2.0, but it is still |
| 75 | + available on .NET Core 2.1. So by using this constant, we can make sure to expose those |
| 76 | + APIs relying on that method on all target frameworks that are able to support them. |
| 77 | + --> |
74 | 78 | <DefineConstants>NETSTANDARD2_1_OR_GREATER;SPAN_RUNTIME_SUPPORT</DefineConstants>
|
75 | 79 | </PropertyGroup>
|
76 | 80 | </When>
|
|
85 | 89 | <ItemGroup>
|
86 | 90 | <PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="5.0.0" />
|
87 | 91 | </ItemGroup>
|
| 92 | + <!-- |
| 93 | + NETCORE_RUNTIME: to avoid issues with APIs that assume a specific memory layout, we define a |
| 94 | + .NET Core runtime constant to indicate either .NET Core 2.1 or .NET Core 3.1. These are |
| 95 | + runtimes with the same overall memory layout for objects (in particular: strings, SZ arrays, |
| 96 | + and ND arrays). We can use this constant to make sure that APIs that are exclusively available |
| 97 | + for .NET Standard targets do not make any assumtpion of any internals of the runtime being |
| 98 | + actually used by the consumers. .NET 5.0 would fall into this category as well, but we don't |
| 99 | + need to include that target as it offers APIs that don't require runtime-based workarounds. |
| 100 | + --> |
88 | 101 | <PropertyGroup>
|
89 |
| - <!-- NETCORE_RUNTIME: to avoid issues with APIs that assume a specific memory layout, we define a |
90 |
| - .NET Core runtime constant to indicate either .NET Core 2.1 or .NET Core 3.1. These are |
91 |
| - runtimes with the same overall memory layout for objects (in particular: strings, SZ arrays, |
92 |
| - and ND arrays). We can use this constant to make sure that APIs that are exclusively available |
93 |
| - for .NET Standard targets do not make any assumtpion of any internals of the runtime being |
94 |
| - actually used by the consumers. .NET 5.0 would fall into this category as well, but we don't |
95 |
| - need to include that target as it offers APIs that don't require runtime-based workarounds.--> |
96 | 102 | <DefineConstants>NETSTANDARD2_1_OR_GREATER;SPAN_RUNTIME_SUPPORT;NETCORE_RUNTIME</DefineConstants>
|
97 | 103 | </PropertyGroup>
|
98 | 104 | </When>
|
|
0 commit comments