我使用在互联网上的虚拟机上运行的Teamcity创建了一个Nuget Server,并创建了将软件包发布到其中的构建。
我还有另一个需要使用该软件包的项目。这个项目也是在Teamcity上构建的。在我的本地Visual Studio中,我添加了Nuget Feed URI, 安装了软件包,一切正常。但是当我尝试在Teamcity上构建时,它显示“找不到软件包”。
所以我的问题是:“如何将自定义Nuget Feed添加到TeamCity构建中?”
c:\Users\$USER\AppData\Roaming\NuGet\NuGet.config
。需要将TeamCity包源条目添加到运行构建的构建代理用户的配置文件中。
编辑:ladenedge记录了一种我最初回答此问题时不存在的好方法。 如果您没有对构建代理进行管理员访问权限或想要按项目配置软件包来源,则此解决方案特别有用。
NuGet现在可以从存储在源代码本身中的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="https://my-nuget-source/nuget/" />
</ItemGroup>
我不想在源代码中添加NuGet.config的feed,因为这是构建基础设施的一部分,而不是应用程序代码的一部分。
我也不想在TeamCity构建代理中添加NuGet.config的feed,因为它很难维护(更新、添加、删除),而且我们有很多构建代理。
对我来说最好的方法是在TeamCity(根项目)中添加%system.PackageSources%,其中包含全局NuGet feed和我的自定义(以分号分隔):
https://www.nuget.org/api/v2/; http://<teamcity_server_name>:81/guestAuth/app/nuget/v1/FeedService.svc
如果您查看NuGet.Targets,您会发现如果定义了$(PackageSources),它将使用它。因此,您可以在TeamCity中将其定义为“system”参数,并将其传递给构建过程。
C:\ Windows \ SysWOW64 \ config \ systemprofile \ AppData \ Roaming \ NuGet \ NuGet.Config
(64位操作系统)或C:\ Windows \ System32 \ config \ systemprofile \ AppData \ Roaming \ NuGet \ NuGet.Config
(32位操作系统)。 - Andrew Cupper