GuiH.ClassLibrary
namespace GuiH.ClassLibrary { public class Class1 { public static void Test() { Console.WriteLine("Hello Nuget!!!"); } } }
我们添加下面一些配置
net6.0 enable enable 1.0.0 true true
// 该命令在GuiH.ClassLibrary项目根目录下执行 dotnet build -c=Release
命令行中也提示了已成功创建包“E:\工作区\GuiH.ClassLibrary\GuiH.ClassLibrary\bin\Release\GuiH.ClassLibrary.1.0.0.nupkg”
GuiH.ClassLibrary.1.0.0.nupkg
推送至nuget仓库,可以自己搭建,也可以是微软官方nuget仓库apikey
详细发布nuget命令参考:dotnet-nuget-push
// $apikey 替换为你的apikey dotnet nuget push ./bin/Release/GuiH.ClassLibrary.1.0.0.nupkg -k $apikey -s https://api.nuget.org/v3/index.json --skip-duplicate 正在将 GuiH.ClassLibrary.1.0.0.nupkg 推送到 'https://www.nuget.org/api/v2/package'... PUT https://www.nuget.org/api/v2/package/ warn : All published packages should have license information specified. Learn more: https://aka.ms/deprecateLicenseUrl. Created https://www.nuget.org/api/v2/package/ 1404 毫秒 已推送包。
例如兼容framwork4.6.1
,修改工程文件如下,注意单词TargetFrameworks
的单复数
// 修改前 net6.0 // 修改后 net6.0;net461
或只支持net461
net461
cicd脚本中核心的两条命令就是上述两个,运行环境安装相应的sdk(.net5/.net6)即可。