我有一个.NET库(
(稍后我还将创建一个NuGet包)
我的问题是:
如何编写此库中的代码?考虑到两个框架使用不同的库/依赖项?
PS:
我在
Products.SDK
),我需要使其与.NET Framework 4.5和.NET Standard 1.4兼容。(稍后我还将创建一个NuGet包)
我的问题是:
如何编写此库中的代码?考虑到两个框架使用不同的库/依赖项?
Will i have two separate projects under the same solution?
Products.SDK.sln
- Products.SDK.NetFramework
- Products.SDK.NetStandard
Will i have only one project, and use
#if
preprocessor directives do define different classes inside the library?namespace Products.SDK { #if NETSTANDARD1_3 public class ProductsApi { public string ApiUrl { get; set; } } #else public class ProductsApi { public string ApiUrl { get; set; } } #endif }
Products.SDK
)编译这两个项目?我认为选项#2更好,但我不确定这是否是正确的方法。PS:
我在
.csproj
文件中指定目标框架。 <PropertyGroup>
<TargetFrameworks>netstandard1.4;net45</TargetFrameworks>
</PropertyGroup>