NuGet私仓搭建使用

Posted 积少成多

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NuGet私仓搭建使用相关的知识,希望对你有一定的参考价值。

一、BaGet简介

  •  BaGet是一个构建于ASP.NET Core 基础上的 NuGet V3 服务器的开源实现
  • release包: https://github.com/loic-sharma/BaGet/releases

二、动手搭建

1. 下载Relese包

  • 在上面选择一个版本,我这边使用的是`v0.4.0-preview2` 最新版本

 2. 运行项目

  • 解压包,然后进入到目
  •  执行:dotnet BaGet.dll

 

3. 查看效果

  •  直接打开http://localhost:5000/    注意:我是修改配置文件 端口改8000
  •  到此私仓就搭建完成了

 

4. 自定义运行端口

  •   编辑`appsettings.json`文件
  •  将红色框的内容取消注释,修改即可

 

三、上传Nuget包

1. 创建测试项目

  • 类型为类库

 

2. 打包项目

  • 右键项目,选择打包:建议选择release模式
  • 打包完成会得到一个nupkg文件

 

 

3. 上传包

  • 在上面打包目录下打开命令行执行:
    dotnet nuget push -s http://localhost:8080/v3/index.json DaXiong.Tools.Configuration.1.0.2.nupkg

4. 项目引用

  • 在VS中工具-选项-NuGet包管理器-程序包源。添加一个源,输入名称,源:http://localhost:8080/v3/index.json 

  •  Nuget包中切换程序包集即可搜索到

 

 

Nexus+Maven私仓

Nexus搭建maven私有库自动打包

maven 项目管理私服工具; Maven项目对象模型(POM);

apache-maven-3.3.9-bin.tar.gz

nexus-2.14.2-01-bundle.tar.gz


1、java 环境变量

/etc/profile

export JAVA_HOME=/usr/local/java

export PATH=$JAVA_HOME/bin:$PATH

export CLASSPATH=.:$java_home/lib/dt.jar:$JAVA_HOME/lib/tools.jar


2、maven 环境变量

/etc/profile

export MAVEN_HOME=/vdb/maven

export MAVEN=$MAVEN_HOME/bin

export PATH=$MAVEN:$PATH


3、版本验证;

# mvn -version


5、配置示例:

[[email protected]]# cat conf/nexus.properties |grep -v ^# |grep -v ^$

application-port=8081

application-host=0.0.0.0

nexus-webapp=${bundleBasedir}/nexus

nexus-webapp-context-path=/nexus

nexus-work=${bundleBasedir}/../sonatype-work/nexus

runtime=${bundleBasedir}/nexus/WEB-INF

storage.diskCache.bufferSize=4096


6、启动进程

进入bin目录运行nexus;

cd nexus/bin

启动

./nexus start

关闭

./nexus stop


URL 访问:

http://10.207.101.100:8081/nexus/index.html 

默认账户:admin 

默认密码:admin123


1、将所有type为proxy的configuration配置选项中DownloadRemoteIndex置为True,然后点击Save保存

其中3rd party选项中可以上传第三方jar包一些maven下载不下来的,公共仓库上找不到的,就可以在3rd party中的Artifacts upload选项卡中上传jar包;


2、新建组  将右边的Available Repositories全部拖到左边点击Save保存 

3、最后右键项目->Run As->Run Configurations双击左边选项卡的Maven Build新建一个


仓库地址/名称

3rd party 第三方的包

http://10.207.101.100:8081/nexus/content/repositories/thirdparty/


Central 中心仓

http://10.207.101.100:8081/nexus/content/repositories/central/


Releases   东财内部包发布仓

http://10.207.101.100:8081/nexus/content/repositories/releases/

 


POM引入东财数据中心发布仓

······

<repositories>

    <repository>

        <id>dc-releases</id>

        <name>dc releases</name>

        <url>http://10.207.101.100:8081/nexus/content/repositories/releases/</url>

    </repository>

    <repository>

        <id>dc-central</id>

        <name>dc central</name>

        <url>http://10.207.101.100:8081/nexus/content/repositories/central/</url>

    </repository>

    <repository>

        <id>dc-thirdparty</id>

        <name>dc thirdparty</name>

        <url>http://10.207.101.100:8081/nexus/content/repositories/thirdparty/</url>

    </repository>

</repositories>

······


引入依赖jar包

······

<dependency>

    <groupId>com.eastmoney.datacenter</groupId>

    <artifactId>eastmoney-dc-utils</artifactId>

    <version>1.0.0</version>

</dependency>

 ····

<dependency>

    <groupId>com.eastmoney.datacenter</groupId>

    <artifactId>eastmoney-dc-elasticsearch</artifactId>

    <version>1.0.0</version>

</dependency>

·····


需要注意的是,当pom.xml中同时配置了releases仓库和snapshots仓库时;

pom.xml文件开头的版本配置<version>1.0.0-SNAPSHOT</version>为build到snapshots库,

而<version>1.0.0</version>**不带-SNAPSHOT的会build到releases库,

如果只配置了releases库而版本号写的是带-SNAPSHOT的,build到最后一步会报400错误。


本文出自 “logs” 博客,请务必保留此出处http://51log.blog.51cto.com/6076767/1918414

以上是关于NuGet私仓搭建使用的主要内容,如果未能解决你的问题,请参考以下文章

如何搭建自己的Maven远程私仓

Nexus+Maven私仓

搭建docker私有仓库

多种方法创建docker registry

使用harbor配置私仓

使用NuGet.Server搭建公司内部的Nuget(包)管理器