在另一个项目中引用一个项目的二进制文件
新手问题:我在 TeamCity 中有 2 个 C# 项目,称它们为 A 和 B。A 包含对 B.dll 的引用。 B 构建得很好。但是,A 无法构建,因为它找不到 B:无法找到程序集“B”
这似乎很简单:如何告诉构建服务器上的项目 A 在哪里可以从 B\bin\Release 中找到二进制文件?
Newbie question : I have 2 C# projects in TeamCity, call them A and B. A contains a reference to B.dll. B builds fine. However, A fails to build because it cannot find B : Could not locate the assembly "B"
It seems really simple : how do I tell my project A on the buildserver where to find the binaries from B\bin\Release?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过创建“工件”和工件依赖项来实现此目的。
如果项目 A 依赖于项目 B,那么您可以使用如下所示的工件路径在项目 B 上创建一个工件:
然后在项目 A 上,您可以使用如下路径设置对 B 的工件依赖项:
并将目标路径设置为项目 A 所在的位置期望找到 B.dll 例如,
您可以做其他很酷的事情,例如使用以下语法自动将所有工件归档到 zip 中:
并通过以下方式访问它们:
所有这些路径都相对于构建目录,因此很容易,您不需要担心 TeamCity guid 文件夹或使用绝对路径。
You do this by creating 'Artifacts' and artifact dependencies.
If project A is dependent on project B, then you create an Artifact on project B using an artifact path like so:
Then on project A you setup a artifact dependency on B with path like:
And set the destination path to be where ever project A is expecting to find B.dll e.g.
You can do other cool stuff like automatically archiving all your artifacts into a zip by using the syntax:
and access them via:
All these paths are relative to build directories so makes it easy and you dont need to worry about the TeamCity guid folders or use absolute paths.
您遇到的问题是,Teamcity 在其自己的临时目录中运行每个构建,并且由于这是随机生成的名称,因此您无法直接设置从一个到另一个的引用。
通常,您会编写一个构建脚本,以正确的顺序构建 A 和 B,然后让 Teamcity 运行该构建脚本。 (由于您使用的是 C#,因此 MSBuild 非常适合此操作)。
另一种方法是在构建结束时将 B.dll 复制到已知位置(例如
c:\currentbuild
),并让 A 始终从此处引用它。您可以在 Teamcity 中设置构建依赖关系,以便在重建 B 时,也会重建 A。The problem you're encountering is that Teamcity runs each build in it's own temporary directory and since this is a randomly generated name you can't set a reference directly from one to the other.
Typically you would write a build script that builds both A and B in the right order and just have Teamcity run that build script. (Since you're using C#, MSBuild is ideal for this).
The alternative would be to have B.dll copied to a known location (e.g.
c:\currentbuild
) at the end of its build and have A always reference it from here. You can set up build dependencies in Teamcity so that if B is rebuilt, A is also rebuilt.