我正在尝试从Team Services获取我的Nuget包但我收到错误

时间:2016-07-28 09:34:43

标签: visual-studio nuget azure-devops

  

无法加载源-my source-的服务索引。密钥无效   在指定的状态下使用。

程序包管理器控制台出现

错误:

  

Install-Package:解决方案中缺少一些NuGet包。   需要恢复包以构建依赖项   图形。在执行任何操作之前恢复软件包。在   line:1 char:1   +安装包Owasp.Esapi -Source我的来源......   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(:) [Install-Package],InvalidOperationException       + FullyQualifiedErrorId:NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

另一个错误: enter image description here

添加VSTS Package Feed并安装软件包的步骤

制作NuGet包

这个过程非常简单。首先,您需要一个包Feed来发送NuGet包。通过单击项目内的Package链接创建它,然后单击“New feed”,为其命名为“default”(我们不太可能在每个项目中创建多个)。保留选项并选择“创建”。

这会创建一个如下所示的供稿网址:https://example.pkgs.visualstudio.com/_packaging/example/nuget/v3/index.json复制它,然后在CI版本中添加2个额外的NuGet构建步骤:

enter image description here

注意它们是不同的步骤。一个是Packager,另一个是Publisher。您可以多次发布它,但只需要打包一次。

在Packager的设置中,将自动包版本控制设置为“使用版本号”,否则它不会覆盖旧版本。

在发布商的设置中,将“Feed类型”设置为“内部NuGet Feed”,然后将您的Feed网址粘贴到网址框中。

在常规选项卡下,将内部版本号格式设置为$(BuildDefinitionName)_ $(Year:yyyy)。$(Month)。$(DayOfMonth)$(Rev:.r)

单击“保存并对构建进行排队”以确保其正常工作。

返回“包”标签,确保您的Feed现在显示了一个包。单击顶部附近的“连接到源”以显示此对话框,然后单击“个人访问令牌:

enter image description here

注意警告。您无法重新显示此密码,因此最好将其记录在某处,理想情况下是KeePass。在开始时复制包括​​nuget位的整个字符串。在依赖项目中设置NuGet后,您将需要这个。

这完成了Nuget包的创建方面,现在可以被其他项目使用。

使用PixelPin NuGet包

现在您有一个生成NuGet包的项目和另一个需要使用它的库,您需要做一些事情。您需要修改本地NuGet配置以在Visual Studio中构建项目,但您还需要将NuGet配置为在VSTS上正确运行,而VSTS将不使用您的本地源文件。

本地设置 右键单击您的项目并选择Manage NuGet packages,您应该使用VS 2015.当页面出现时,单击右侧的cog以显示您的Feed设置。在包源下,如果您还没有它,请添加一个具有合适名称的新源,并粘贴您之前用于创建包的JUST THE URL。单击“确定”后,可能会要求您输入凭据。使用用户名(通常是“支持”)和您之前获得的密码。这应该允许您浏览Feed并选择所需的库。

选择所需的库应该按照正常的NuGet包安装它,并且现在应该构建本地项目(假设您当然没有其他错误)。

VSTS的设置 VSTS online不会看到或使用您的NuGet配置,因此您需要添加一些文件,进行设置并配置VSTS版本以使用它们。

1) Create a nuget.config file in the root of your solution, you can copy one from another project.
2) Also copy NuGet.exe from another project and put it in the root. Reference both of these files in your solution so you can add them to source control.
3) Run up a command prompt, change directory into the root of your solution and run the command you copied earlier from the Connect to Feed dialog. It will be something like this: NuGet sources Add -Name feedName -Source https://example.pkgs.visualstudio.com/_packaging/test/nuget/v3/index.json -UserName support -Password 324oui25b3bi1235ob -ConfigFile .\nuget.config
4) NOTE the last bit which points to your solution copy of nuget.config rather than the default which will be your local machine copy. If it works OK, open the config file to check that you have an entry under packageSources for the name you specified and an entry for packageSourceCredentials with a username and encrypted password.
5) If you somehow get it wrong, you can delete the credentials and package source manually and run the command again but be careful not to remove any other entries that are already there. You can also use NuGet sources Update instead of Add, which should update what is already there.
6) Once you have done this, check in the nuget.config and nuget.exe so they are copied up to the VSTS project. If you check everything in, the next CI build will probably fail but don't worry.
7) Edit your build again and click on the NuGet restore step. Edit the "Path to NuGet.config" and navigate to the nuget.config you just uploaded. (You won't use NuGet.exe on VSTS but it's there in case you need to use it locally again).

对另一个构建进行排队,并确保程序包还原步骤正常工作,并且您的依赖程序包现在作为正常构建的一部分被引入!

0 个答案:

没有答案