日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

发布 Rafy .NET Standard 版本 Nuget 包

發(fā)布時間:2023/12/4 asp.net 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 发布 Rafy .NET Standard 版本 Nuget 包 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

去年年中,Rafy 框架的源碼就已經(jīng)支持了 Net Standard 2.0 版本。其開源代碼也已經(jīng)上傳到 Github 中:https://github.com/zgynhqf/rafy/tree/NetStandard2.0?。但是這都只是在源碼層面支持 NS2.0,并沒有發(fā)布其正式的 Nuget 包。要使用這個版本的開發(fā)者,不得不自己下載源碼進行編譯。

最近,使用 Net Core 的開發(fā)者越來越多。所以我們決定發(fā)布一個正式的 Nuget 包,以方便 Net Core 的開發(fā)都可以方便地下載、更新 Rafy 框架進行使用。

發(fā)布后,開發(fā)者在 Nuget 中再搜索 Rafy 的最新版本時,就已經(jīng)支持 Net Standard 2.0 了:

項目支持多版本的改造步驟

過程中其實沒有想到,要發(fā)布一個同時支持 Net Standard 2.0 和 Net Framework 4.5 版本的 Nuget 包,還是比較繁瑣的。需要將原來的兩個分支的代碼合并到一起,并通過預處理命令來分別編譯為不同版本。

下面,簡單記錄一下一些重要的步驟:

  • 創(chuàng)建并使用新的 Net Standard 項目文件格式來創(chuàng)建。

  • 修改 Rafy.csproj 文件,使其支持多個 .NET 版本:

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup><TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
  • Rafy.csproj 文件中,為不同的版本添加不同的引用:

<ItemGroup Condition="'$(TargetFramework)' == 'net45'"><Reference Include="PresentationFramework" /><Reference Include="System" /><Reference Include="System.Configuration" /><Reference Include="System.Core" /><Reference Include="System.Runtime.Caching" /><Reference Include="System.Runtime.Serialization" /><Reference Include="System.ServiceModel" /><Reference Include="System.Transactions" /><Reference Include="System.Web" /><Reference Include="System.Xaml" /><Reference Include="System.Xml.Linq" /><Reference Include="System.Data.DataSetExtensions" /><Reference Include="Microsoft.CSharp" /><Reference Include="System.Data" /><Reference Include="System.Xml" /><Reference Include="WindowsBase" /><PackageReference Include="Castle.Core" Version="4.1.1" /><PackageReference Include="Newtonsoft.Json" Version="10.0.3" /></ItemGroup><ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'"><PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" /><PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" /><PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" /><PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0" /><PackageReference Include="Newtonsoft.Json" Version="10.0.3" /><PackageReference Include="System.ComponentModel" Version="4.3.0" /><PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" /><PackageReference Include="System.Data.Common" Version="4.3.0" /><PackageReference Include="Castle.Core" Version="4.1.1" /><PackageReference Include="System.Data.SqlClient" Version="4.4.0" /></ItemGroup>
  • 還可以自定義一些縮寫的常量:

<PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'"><DefineConstants>NS2</DefineConstants></PropertyGroup>

  • 修改合并后的項目中的所有相關代碼,都使用預處理命令來區(qū)別不同的版本,如:

? ? ? ? ? private void EnsureLoaded() ? ? ? ?
?
{ ? ? ? ? ? ?
? ? ? ? ? ? if (_section == null){ ?
? ? ? ? ? ? ?#if NET45_section = ConfigurationManager.GetSection("rafy") as RafyConfigurationSection; ? ? ? ? ? ? ? ? ?
? ? ? ? ? ? ? if (_section == null) _section = new RafyConfigurationSection(); ? #endif#if NS2var rafyRawSection = ConfigurationHelper.Configuration.GetSection("rafy"); ? ?
? ? ? ? ? ? ? ? ? if (rafyRawSection == null){ ? ? ? ? ? ? ? ? ? ? ? throw new InvalidProgramException("配置文件中沒有 rafy 配置節(jié),請檢查配置文件。");}_section = new RafyConfigurationSection();rafyRawSection.Bind(_section); ?
? ? ? ? ? ? ? ? ? #endif}}
  • 配置項目為編譯時生成對應的 Nuget 包。

  • 生成,并發(fā)布。最終生成的 Nuget 包格式是這樣的:

通過上述幾步,就使得 Rafy 框架支持了 Net Standard 版本了。同時,我們還把 Rafy 中的一些其它公共插件也都支持了多版本。以后會不定期升級每一個插件。

原文地址: http://www.cnblogs.com/zgynhqf/p/9015478.html


.NET社區(qū)新聞,深度好文,歡迎訪問公眾號文章匯總 http://www.csharpkit.com

總結

以上是生活随笔為你收集整理的发布 Rafy .NET Standard 版本 Nuget 包的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。