珂珂的个人博客 - 一个程序猿的个人网站

gitea 作为nuget服务器

由于我项目引用了本地局域网nuget服务器,而这个nuget服务器是.net framework 的。  在Linux服务器上将代码git clone 下来,发布到docker中。使用docker build -t xxxxx .

会导致找不到包  No packages exist with this id in source(s): nuget.org  所以需要在外网环境或Linux服务器自身环境发布一个nuget服务器,这就想到了gitea

首先在本地电脑上添加一个nuget源为gitea服务器

dotnet nuget add source --name gitea --username xxxxx --password xxxxx https://git.kecq.com/api/packages/xxxxx/nuget/index.json

xxxx为gitea的用户名和密码

Linux中运行会提示

error: Password encryption is not supported on .NET Core for this platform. The following feed try to use an encrypted password: 'gitea'. You can use a clear text password as a workaround.

error:   Encryption is not supported on non-Windows platforms.

需要在上面命令中加上--store-password-in-clear-text

dotnet nuget add source --name gitea --username xxxx --password  123456 --store-password-in-clear-text https://git.kecq.com/api/packages/xxxxx/nuget/index.json


如果要移除上面添加的源用

dotnet nuget remove source gitea

然后在visual studio 中生成包,在项目中点击右键选择打包(P)  菜单可以生成包。

然后再发布到gitea上

dotnet nuget push --source gitea xxxxx.2.0.4.nupkg

后面可以用绝对路径


但我觉得这样太麻烦还是想集成在visual studio 上。

先新建一个bat文件,内容如下

rmdir /s /q D:\nuget\packer\temp

dotnet pack %1  -o D:\nuget\packer\temp

dotnet nuget push --source gitea D:\nuget\packer\temp\%~2.*.nupkg

然后visual studio 点击工具->外部工具   添加下面截图类似的

第三行参数为

【Arguments】 $(ProjectDir)$(ProjectFileName) $(TargetName)

注意第三个$前有一个空格,建议原封不动的贴过去!!

但我这visual studio 控制台中会有乱码,不知如何解决


另外我发现在 Linux 中添加了nuget源

用docker build -t myblog . 

仍会报出 error NU1101: Unable to find package FYJ.Common. No packages exist with this id in source(s): nuget.org [/src/Blogs.UI.Main/Blogs.UI.Main.csproj]

我在/root/.nuget/packages 中放了包也仍然会报找不到此包

发现是运行 dotnet restore时出错

我按照官方文档在解决方案根目录下增加了nuget.config 文件,因为我的dockerfile是放在解决方案sln文件所在目录

按照官方文档nuget.config 文件参考 | Microsoft Learn

我的内容为

<config>
    <add key="globalPackagesFolder" value="~/.nuget/packages" /> 
</config>

但是手动运行dotnet restore "./Blogs.UI.Main/Blogs.UI.Main.csproj"   发现与docker build -t myblog . 报的信息不一致

这里的nuget.config  xml感觉不应该是官方文档的config根节点,所以我改成configuration 后感觉是读到了的,而且之前添加的源似乎也起作用了。怀疑是 docker build -t 使用的环境是docker中  所以找不到源?


上一篇:个人代码全部开源

下一篇:AMD 5800H 小主机折腾记


0 评论

查看所有评论

给个评论吧