.net 如何将自定义 nuget 提要添加到 TeamCity 构建中?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14548324/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to add the custom nuget feed to TeamCity build?
提问by Eugene
I have created a Nuget Server using Teamcity (running on a virtual machine in internet) and created the build that publishes a package into it.
我使用 Teamcity(在 Internet 中的虚拟机上运行)创建了一个 Nuget 服务器,并创建了将包发布到其中的构建。
I also have another project that needs to use that package. This project is built on teamcity as well. On my local Visual Studio I added the nuget feed uri, installed the package and everything works fine. But when I try to build it on teamcity it says that "Package not found".
我还有另一个项目需要使用该包。这个项目也是建立在teamcity上的。在我本地的 Visual Studio 上,我添加了 nuget feed uri,安装了包,一切正常。但是当我尝试在 teamcity 上构建它时,它说“找不到包”。
So my question is : "How to add the custom nuget feed to TeamCity build?"
所以我的问题是:“如何将自定义 nuget 提要添加到 TeamCity 构建中?”
采纳答案by John Hoerr
The NuGet package sources are configured through Visual Studio, but they're stored in a per-user configuration file, found at c:\Users\$USER\AppData\Roaming\NuGet\NuGet.config. The entry for the TeamCity package source needs to be added to the config file of the build agent user that's running your builds.
NuGet 包源是通过 Visual Studio 配置的,但它们存储在每个用户的配置文件中,位于c:\Users\$USER\AppData\Roaming\NuGet\NuGet.config. TeamCity 包源的条目需要添加到运行构建的构建代理用户的配置文件中。
- On your local machine, open the Nuget.config file for your user
- Copy the entry for the TeamCity package source to the clipboard
- On the build agent, open the NuGet.config file for the user that's executing your TeamCity builds
- Paste in the TeamCity package source entry. Save & quit.
- Run the build again. It should now be able to find the package.
- 在您的本地计算机上,为您的用户打开 Nuget.config 文件
- 将 TeamCity 包源的条目复制到剪贴板
- 在生成代理上,为正在执行 TeamCity 生成的用户打开 NuGet.config 文件
- 粘贴 TeamCity 包源条目。保存并退出。
- 再次运行构建。它现在应该能够找到包。
EDIT:ladenedge documents a good solution that didn't exist when I originally answered this question. The solution is especially useful if you don't have admin access to the build agent or want to configure package sources on a per-project basis.
编辑:ladenedge 记录了一个很好的解决方案,当我最初回答这个问题时并不存在。如果您没有对构建代理的管理员访问权限或想要在每个项目的基础上配置包源,则该解决方案特别有用。
回答by ladenedge
NuGet can now read sources from the NuGet.targetsfile stored with the source itself as explained in the answerto a duplicate question.
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>
回答by Ivan
I didn't want to add feed in NuGet.configin source code as this is part of build infrastructure and not part of application code.
我不想在源代码中的NuGet.config中添加提要,因为这是构建基础结构的一部分,而不是应用程序代码的一部分。
Neither I wanted to add feed in NuGet.configon TeamCity build agents as it's difficult to maintain (update, add, remove), plus we have many build agents.
我也不想在 TeamCity 构建代理的NuGet.config 中添加提要,因为它很难维护(更新、添加、删除),而且我们有很多构建代理。
What worked the best for me - adding %system.PackageSources%in TeamCity (on Root project) containing both global nuget feed and my custom (semicolon-separated):
什么最适合我 -在 TeamCity(在 Root 项目上)添加%system.PackageSources%,其中包含全局 nuget 提要和我的自定义(分号分隔):
https://www.nuget.org/api/v2/; :81/guestAuth/app/nuget/v1/FeedService.svc" rel="noreferrer">http://<teamcity_server_name>:81/guestAuth/app/nuget/v1/FeedService.svc
https://www.nuget.org/api/v2/; :81/guestAuth/app/nuget/v1/FeedService.svc" rel="noreferrer">http://<teamcity_server_name>:81/guestAuth/app/nuget/v1/FeedService.svc
If you look at NuGet.Targets, you'll see that it uses $(PackageSources) if it's defined. So you define it as "system" parameter in TeamCity and it gets passed to the build process.
如果您查看NuGet.Targets,您会发现它使用了 $(PackageSources)(如果已定义)。因此,您在 TeamCity 中将其定义为“系统”参数,并将其传递给构建过程。
回答by Hasan A Yousef
In my case, the DLL file is saved here:
C:\Users\user_account\.nuget\packages\package-name\package_version\lib\netcoreapp1.0\assembly_name.dll
就我而言,DLL 文件保存在此处:
C:\Users\user_account\.nuget\packages\package-name\package_version\lib\netcoreapp1.0\assembly_name.dll

