简体   繁体   English

在Visual Studio外部管理Nuget包

[英]Manage Nuget Packages Outside Visual Studio

My organization wants to segregate all the development machines on a network without internet access. 我的组织希望隔离没有网络访问权限的网络上的所有开发机器。

I found this article that gives that gives some nuget host product, so that the packages are available offline. 我发现这篇文章给出了一些nuget主机产品,以便可以脱机使用这些软件包。

My problem is that I can't find a way to manage the package update, because the machines that have and internet access won't have Visual studio installed. 我的问题是,我找不到管理软件包更新的方法,因为具有Internet访问权限的计算机不会安装Visual Studio。

I was looking if there is a tool that reads a folder where all nupkg files are stored and check if a newer version is available and downloads it, or otherwise reads a manually created packages.config file checks for newer version and download them on a folder. 我正在寻找是否有一种工具可以读取存储所有nupkg文件的文件夹并检查是否有较新版本并下载它,或者读取手动创建的packages.config文件来检查较新版本并将其下载到文件夹中。

Does anyone have an idea how to manage nuget packages in this way? 有谁知道如何以这种方式管理nuget包? I spent the last week trying to find a way but I had no look. 我花了最后一个星期试图找到一种方法,但我没有看。

Does anyone have an idea how to manage nuget packages in this way? 有谁知道如何以这种方式管理nuget包?

According to the NuGet CLI reference : 根据NuGet CLI参考

The update command also updates assembly references in the project file, provided those references already exist. 如果这些引用已经存在,则update命令还会更新项目文件中的程序集引用。

So when we use NuGet.exe update the package, we are not only need the packages.config but also need the solution/project, otherwise, you will get the error: 因此,当我们使用NuGet.exe更新程序包时,我们不仅需要packages.config,还需要解决方案/项目,否则,您将得到以下错误:

"Unable to locate project file for 'D:\\NuGetServer\\packages.config' “无法找到'D:\\ NuGetServer \\ packages.config'的项目文件

You can copy a simple project from the machine, which have Visual Studio installed, then use below command line to update the nuget package in the package.config file: 您可以从安装了Visual Studio的计算机中复制一个简单的项目,然后使用以下命令行更新package.config文件中的nuget软件包:

nuget update "YourProjectPath\packages.config"

But NuGet will update the packages into the packages folder under the solution folder by default, so we need change the packages folder to the folder where all nupkg files are stored before update packages. 但是默认情况下,NuGet会将软件包更新到解决方案文件夹下的packages文件夹中,因此我们需要在更新软件包之前将packages文件夹更改为所有nupkg文件存储的文件夹。

Detail steps : 详细步骤

  1. Download the nuget.exe from nuget.org , set it to your local machines. nuget.org下载nuget.exe ,将其设置为本地计算机。

  2. Create a NuGet folder under the path %appdata% , add the NuGet.Config file and change the packages folder by repositoryPath , just set it " D:\\NuGetServer ": 在路径%appdata%下创建一个NuGet文件夹,添加NuGet.Config文件,然后通过repositoryPath更改packages文件夹,只需将其设置为“ D:\\NuGetServer ”:

 <?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" /> </packageSources> <config> <add key="repositoryPath" value="D:\\NuGetServer" /> </config> </configuration> 
  1. Copy a solution from other machine, add the packages in to the package.config file: 从其他计算机复​​制解决方案,将软件包添加到package.config文件中:

     <?xml version="1.0" encoding="utf-8"?> <packages> <package id="EntityFramework" version="6.1.0" targetFramework="net45" /> <package id="Newtonsoft.Json" version="8.0.3" targetFramework="net45" /> <package id="NUnit" version="3.7.0" targetFramework="net45" /> </packages> 
  2. Open a CMD file, switch to the path where NuGet is stored in step 1, then use the update command: 打开一个CMD文件,在步骤1中切换到NuGet的存储路径,然后使用update命令:

在此处输入图片说明

You will find packages in the packages.config are updated to the latest version. 您将在packages.config中找到软件包。这些软件包已更新为最新版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM