为什么对于相同的解决方案,VS2008 构建与 msbuild 不同?

发布于 2024-08-07 11:29:22 字数 1603 浏览 1 评论 0原文

我继承了一个由多个项目组成的解决方案,混合了 VB.NET 和 C#。使用 IDE“构建解决方案”按钮可以很好地构建。它不会使用“msbuild foo.sln”从命令行构建;错误消息表明项目 A(引用项目 B)找不到项目 B。事实上,在使用“msbuild”后检查“bin”文件夹的内容并将其与使用 IDE 后的内容进行比较后,我可以发现大量DLL丢失,包括B.dll。

简而言之:项目 A 确实引用了项目 B,但 B.DLL 仅在使用 IDE 时复制到 A 的 bin 目录,而在使用 msbuild 时则不会。如果我在 IDE 构建后运行 msbuild,它会起作用,因为引用的 DLL 已被复制。

我天真地相信“msbuild foo.sln”与 foo.sln 的 IDE 版本相同。事实似乎并非如此。 Stack Overflow 上至少还有其他三个类似的问题,但我无法引用它们,因为“新用户只能发布一个超链接”(!!)。对不起。以下是问题标题,以便您可以自行搜索:

现在我的问题是:

  1. 在哪里可以找到“构建解决方案”时 Visual Studio 所做的准确记录?
  2. 配置 Visual Studio 和持续集成服务器(例如 Hudson)以使开发人员工作站构建与 CI 构建相同的最佳实践是什么?

我来自 Unix 世界,所以请随时给我新手指点。

I have inherited a solution consisting of several projects, a mix of VB.NET and C#. It builds fine using the IDE "Build Solution" button. It does not build from the command line using "msbuild foo.sln"; the error message indicates that project A (which references project B) can't find project B. Indeed, upon examining the contents of the "bin" folder after using "msbuild" and comparing it against the contents after using the IDE, I can find a whole lot of DLLs missing, including B.dll.

In short: the project A does have a reference to project B, but B.DLL is only copied to A's bin directory when using the IDE, but not when using msbuild. If I run msbuild after an IDE build it works, since the referenced DLLs are copied.

I had naively believed that "msbuild foo.sln" is the same as an IDE build of foo.sln. That doesn't seem to be the case. There are at least three other similar questions here on Stack Overflow but I can't reference them because "new users can only post one hyperlink" (!!). Sorry. Here are the question titles so you can search yourself:

Now here are my questions:

  1. Where can I find documented precisely what Visual Studio does when you "Build Solution"?
  2. What are the best practices for configuring Visual Studio and a Continuous Integration server (e.g. Hudson) so that the developer workstation builds are the same as the CI builds?

I'm coming from the unix world, so feel free to send me newbie pointers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两人的回忆 2024-08-14 11:29:22

John Weldoon 是正确的,Visual Studio 和 MSBuild 的构建非常相似,但有时可能不同。一种情况是 VS 对于引用更加宽松。假设你有三个项目 A、B 和 C。A 依赖于 B,B 依赖于 C。然后在 VS 中,如果项目 A 仅引用 B,那么它可以,但 MSBuild 可能会抱怨,因为它缺少对项目 C 的引用。
存在一些差异的一个重要原因是 VS 有一个主机编译器,用于帮助增强 IDE 体验。如果您想要降级 IDE 体验,则可以将 MSBuild 属性 UseHostCompilerIfAvailable 设置为 false,以强制 Visual Studio 使用 MSBuild。例如,

<PropertyGroup>
    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>

我不建议这样做,但如果您绝对需要它,则可以使用该选项。

John Weldoon is correct the builds from Visual Studio and MSBuild are very similar but can be different at times. One case is that VS is more lienent with respect to referecnes. Lets say you have three projecta A, B and C. A depends on B and B depends on C. Then in VS if project A just references B then its OK but MSBuild may complain because it is missing a reference to project C.
One of the big reasons that there is some difference is because VS has a host compilier that is used to help enahce the IDE experience. If you are wiling to downgrade your IDE experience then you can set the MSBuild property, UseHostCompilerIfAvailable, to false to force Visual Studio to use MSBuild. Such as

<PropertyGroup>
    <UseHostCompilerIfAvailable>false</UseHostCompilerIfAvailable>
</PropertyGroup>

I don't suggest this but if you absolutely need it the option is available to you.

清风不识月 2024-08-14 11:29:22

在我看来,您应该使用 msbuild 构建 CI 脚本和一般构建脚本。

IDE 并不总是使用与 msbuild 引擎相同的引擎进行构建,尽管我认为他们正在越来越多地这样做。

In my opinion you should build your CI scripts, and general build scripts with msbuild.

The IDE does not use the same engine for building all the time as the msbuild engine, although I think they are working on doing it more and more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文