NuGet包还原找不到包,没有源。

28

我的TeamCity NuGet feed上有一个由TeamCity构建的包,但是一个依赖的TC项目在还原包时无法看到它。

[14:05:02][Exec] E:\TeamCity-BuildAgent\work\62023563850993a7\Web.nuget\nuget.targets(88, 9): 无法找到软件包 'MarkLogicManager40' 的版本 '1.0.17.0'。

[14:05:02][Exec] E:\TeamCity-BuildAgent\work\62023563850993a7\Web.nuget\nuget.targets(88, 9): 错误 MSB3073: 命令“''E:\TeamCity-BuildAgent\work\62023563850993a7\Web.nuget\nuget.exe' install 'E:\TeamCity-BuildAgent\work\62023563850993a7\ProductMvc\packages.config' -source '' -RequireConsent -solutionDir 'E:\TeamCity-BuildAgent\work\62023563850993a7\Web\ ''”已退出,代码为1。

请注意,NuGet命令行中的source参数为空。这可能是原因吗?


将自定义 NuGet 源添加到 TeamCity 的方法此前已经有解答 - John Hoerr
现在我知道答案,也知道问题。 - Luke Puplett
2个回答

43

截至今日,NuGet.targets有以下指定自定义源的方法:

<ItemGroup Condition=" '$(PackageSources)' == '' ">
    <!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
    <!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->

    <PackageSource Include="https://nuget.org/api/v2/" />
    <PackageSource Include="\\MyShare" />
    <PackageSource Include="http://MyServer/" />
</ItemGroup>

另一种选择是将 NuGet.config 放置在解决方案文件旁边:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="MyShare" value="\\MyShare" />
    <add key="MyServer" value="http://MyServer" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)"  />
  </activePackageSource>
</configuration>

1
@granadaCoder:使用“-Source”参数。 - abatishchev
3
谢谢。我不知道你可以提供多个分号分隔的源(Source)。对于未来的读者:::-Source "https://www.nuget.org/api/v2/;http://myprivateserver/nuget/" - granadaCoder
1
这适用于自动包恢复吗,还是只适用于 MSBuild 集成的包恢复? - Dave New
1
我认为供稿来源与自动恢复无关。因此应该适用于两者。 - abatishchev
3
在NuGet安装程序步骤中,现在有一个"软件包源"字段,您可以填写以让Team City使用自定义Feed。 - archangel76
显示剩余2条评论

9
显然,NuGet自定义源并不是通过解决方案或项目文件中的任何内容,或者解决方案中的nuget.config来设置的,而是在开发人员配置文件(nuget.config)中设置。
在TeamCity上,代理程序没有检查此配置文件,也没有写入其中,以确保它包含TeamCity服务器本身的源。
因此,在使用自定义TC源进行TC软件包还原时,无法“轻松工作”。 您必须花费数百英镑的客户资金来追踪所有这些,并将您的nuget.config从您的个人资料复制到运行构建代理的用户帐户的资料夹中。
非常糟糕。

7
要让TeamCity使用已检入的源代码运行,可以将自定义包源添加到NuGet.targets文件中。另一种方法是在编译解决方案之前使用自定义的NuGet Installer运行程序作为构建步骤。不确定为什么NuGet.config文件中的包源会被忽略,可能是因为自定义的.targets文件没有导入或读取它。 - Matt Ward
我改变了答案以反映更好的方法。 - Luke Puplett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接