
# 通过客户端上传/下载NuGet组件
CodeArts Artifact支持与本地NuGet客户端对接，用户A可以通过客户端的方式将本地NuGet客户端中的私有组件上传至CodeArts Artifact私有依赖库，其他用户再通过客户端的方式从CodeArts Artifact私有依赖库下载用户A上传的NuGet组件，实现NuGet组件的共享或传递。
#### NuGet组件介绍
NuGet是.NET生态系统中的包管理器，它允许开发者方便地发布、分享和使用各种 .NET组件和库。NuGet制品包是这些组件和库的标准发布格式。
#### 约束与限制
不同用户账号的私有依赖库仓库密码不同，当用户以不同账号访问私有依赖库时，如果需要使用仓库密码，则需要在各仓库"操作指导"中重新下载配置文件获取仓库密码。
#### 前提条件
- 使用客户端工具为nuget、dotnet，请确保已安装nuget、dotnet。
- 已[创建NuGet仓库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0008.html)。
- 需要具备当前仓库的"下载/查看"权限，如需获取"下载/查看"的权限，请参考[配置私有依赖库权限](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0047.html)配置。
 
#### 通过NuGet客户端上传组件
使用客户端工具为nuget，请确保已安装nuGet。
1. 使用华为云账号[访问CodeArts Artifact的私有依赖库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0007.html#cloudartifact_01_0007__section1789618380209)。
2. 在私有依赖库页面选择对应的NuGet仓库。
3. 单击页面右侧"操作指导"。
4. 在"操作指导"对话框，"选择依赖管理工具"为"nuget"。
5. 单击"下载配置文件"，下载配置文件"NuGet.txt"。 
   ![](https://support.huaweicloud.com/usermanual-cloudartifact/zh-cn_image_0000002513699510.png "点击放大")
   
   
6. 打开下载的配置文件，使用如下命令，进行源的添加。 
   ```
   ##----------------------NuGet add source----------------------##
   nuget sources add -name {repo_name} -source {repo_url} -username {user_name} -password {repo_password}
   ```
   
   
7. 使用如下命令进行包的上传，替换\<PATH_TO_FILE\>为要上传文件的路径，执行上传语句（若有配置源，-source后的参数可使用配置的源名称）。 
   ```
   ##----------------------NuGet Download----------------------##
   nuget push <PATH_TO_FILE> -source <SOURCE_NAME>
   ```
   
   
 
#### 通过NuGet客户端下载组件
使用客户端工具为nuget，请确保已安装nuget。
1. 使用华为云账号[访问CodeArts Artifact的私有依赖库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0007.html#cloudartifact_01_0007__section1789618380209)。
2. 在私有依赖库页面选择对应的NuGet仓库。
3. 单击页面右侧"操作指导"。
4. 在"操作指导"对话框，"选择依赖管理工具"为"nuget"。
5. 单击"下载配置文件"，下载配置文件"NuGet.txt"。 
   ![](https://support.huaweicloud.com/usermanual-cloudartifact/zh-cn_image_0000002513700638.png "点击放大")
   
   
6. 打开配置文件，找到NuGet add source下的命令，进行源的添加。 
   ```
   ##----------------------NuGet add source----------------------##
   nuget sources add -name {repo_name} -source{repo_url} -username {user_name} -password {repo_password}
   ```
   
   
7. 打开配置文件，找到NuGet Download下的语句，替换\<PACKAGE\>为要下载组件的名称，执行下载语句（若有配置源，-source后的参数可使用配置的源名称）。 
   ```
   ##----------------------NuGet Download----------------------##
   nuget install <PACKAGE>
   ```
   
   
 
#### 通过dotnet客户端上传组件
使用客户端工具为dotnet，请确保已安装dotnet。
dotnet客户端需要添加信任服务器证书，才可以使用。
- windows信任证书步骤： 1.导出服务器证书。
  ```
  openssl s_client -connect {host}:443 -showcerts </dev/null 2>/dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' |openssl x509 -outform PEM >mycertfile.pem
  openssl x509 -outform der -in mycertfile.pem -out mycertfile.crt
  ```
  mycertfile.pem和mycertfile.crt即为下载的证书。
  2.windows需要使用powershell 添加证书信任。
  添加证书
  ```
  Import-Certificate -FilePath "mycertfile.crt" -CertStoreLocation cert:\CurrentUser\Root
  ```
  
1. 使用华为云账号[访问CodeArts Artifact的私有依赖库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0007.html#cloudartifact_01_0007__section1789618380209)。
2. 在私有依赖库页面选择对应的NuGet仓库。
3. 单击页面右侧"操作指导"。
4. 在"操作指导"对话框，"选择依赖管理工具"为"dotnet"。
5. 单击"下载配置文件"，下载配置文件"dotnet.txt"。 
   ![](https://support.huaweicloud.com/usermanual-cloudartifact/zh-cn_image_0000002545299389.png "点击放大")
   
   
6. 打开配置文件，找到dotnet add source下的命令，进行源的添加。 
   ```
   ##----------------------dotnet add source----------------------##
   dotnet nuget add source {repo_url} add -n {repo_name} -u {user_name} -p {repo_password}
   ```
   
   
7. 找到dotnet upload下的语句，替换\<PATH_TO_FILE\>为要上传文件的路径，执行上传语句。 
   ```
   ##----------------------dotnet upload----------------------##
   dotnet nuget push <PATH_TO_FILE> -s {repo_name}
   ```
   
   
 
#### 通过dotnet客户端下载组件
使用客户端工具为dotnet，请确保已安装dotnet。
1. 使用华为云账号[访问CodeArts Artifact的私有依赖库](https://support.huaweicloud.com/usermanual-cloudartifact/cloudartifact_01_0007.html#cloudartifact_01_0007__section1789618380209)。
2. 在私有依赖库页面选择对应的NuGet仓库。
3. 单击页面右侧"操作指导"。
4. 在"操作指导"对话框，"选择依赖管理工具"为"dotnet"。
5. 单击"下载配置文件"，下载配置文件"dotnet.txt"。 
   ![](https://support.huaweicloud.com/usermanual-cloudartifact/zh-cn_image_0000002513860552.png "点击放大")
   
   
6. 打开配置文件，找到dotnet add source下的命令，进行源的添加。 
   ```
   ##----------------------dotnet add source----------------------##
   dotnet nuget add source {repo_url} add -n {repo_name} -u {user_name} -p {repo_password}
   ```
   
   
7. 找到dotnet download下的语句，替换\<PACKAGE\>为要下载组件的名称，执行下载语句。 
   ```
   ##----------------------dotnet download----------------------##
   dotnet add package <PACKAGE>
   ```
   
   
 
