为什么我不应该在 CI 服务器上安装 Visual Studio?
许多刚接触 CI(持续集成)的人在他们的 CI 服务器上安装 VS(Visual Studio),“因为需要它来编译代码”。 MSTest 是这里提到的一个常见参考。
为什么我不应该在 CI 服务器上安装 VS(或者一般来说,任何非开箱即用的软件)?
(这个问题显然之前没有被问过,所以我添加它以供参考。如果它已经存在,抱歉,我错过了它,请合并。如果一段时间内没有对此问题提供答案,我可以自己添加一个)
A lot of people new to CI (Continuous Integration) install VS (Visual Studio) on their CI server "because it is required to compile the code". MSTest is a common reference brought up here.
Why should I not install VS (or generally speaking, any software not out-of-the-box) on my CI server?
(This question has not been asked before apparently, so I'm adding it for reference. If it already exists, sorry, I missed it, please merge. If no answer is provided to this question within some time I can add one myself)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为你不需要。 Visual Studio 许可证非常昂贵,因此将一个许可证放在无人使用的服务器上只是一种浪费。有几个论点解释了为什么您仍然需要在持续集成上安装完整的 Visual Studio 实例服务器 - 但这里是他们的反驳论点:
原因 1:我需要它来编译。
现实:不,你不知道。您需要 MSBuild 来编译,但这是 在 Windows SDK 中免费提供。请注意,不同的操作系统和 .NET 版本有多个版本,因此请小心下载正确的版本。
原因 2:我需要它在服务器上进行快速修复。
现实:不,你不知道。您不应该在服务器上进行快速修复 - 您应该从版本控制系统中签出,进行修复,在本地构建和运行测试,直到它正常工作,签入并让 CI 系统执行此操作剩下的给你。 这就是您拥有 CI 系统的原因。
原因 3:如果没有 Visual Studio,我无法在 CI 服务器上运行 MSTest。
现实:错误。 AFAIK,MSTest 运行器也是 SDK 的一部分(至少在我们的 CI 服务器上看起来是这样的 - 尽管我无法验证它,因为我们目前没有任何测试......)。然而,快速谷歌搜索发现这篇博客文章解释了如何做到这一点也没有 SDK。我还没有详细阅读它,所以我不能保证它有效,或者它是合法的。你已被警告过。
欢迎在评论中添加更多理由,我会予以反驳。
Because you don't need to. A Visual Studio license is pretty expensive, so having one just lying around on a server where no one's using it is just a waste.There are a couple of arguments why you would still need to install a full blown Visual Studio instance on your Continuous Integration server - but here are their counter arguments:
Reason 1: I need it to compile.
Reality: No, you don't. You need MSBuild to compile, but that is available for free, in the Windows SDK. Note that there are several versions for different operative systems and .NET versions, so be careful to download the correct one.
Reason 2: I need it to make quick fixes on the server.
Reality: No, you don't. You shouldn't make quick fixes on the server - you should check out from your version control system, make the fix, build and run tests locally until it works, check in, and have the CI system do the rest for you. That's why you have a CI system.
Reason 3: Without Visual Studio, I can't run MSTest no my CI server.
Reality: Wrong. AFAIK, the MSTest runner is also part of the SDK (at least that's what it seems like on our CI server here - although I can't verify it since we don't have any tests at the moment...). However, a quick googling found this blog post which explains how to do it without the SDK as well. I haven't read through it in detail, so I can't promise that it works, or that it's legal. You have been warned.
Feel free to add more reasons in comments, and I'll counter them.
无论如何,您可能需要安装 Visual Studio,出于实用性,
我打算尝试反驳 @TomasLycken 在评论中发布的已接受答案,但发现我需要更多空间来讨论。尽管我在技术上同意 @TomasLycken 的主张,但在这里,我将列出一些我发现很难在 CI 服务器上安装的依赖项 - 并让您来决定接受的答案有多正确......
< strong>1 - 'mshtml'主互操作程序集
您可以在这个SO问题中看到我在构建输出中遇到的问题 我创建并回答了。请注意,我花了几个小时弄清楚如何注册所需的 PIA - 这是在服务器上运行来自我的 V.Studio 安装的一些 .exe 的结果 - 嗯嗯嗯
上下文: 我有一个使用 Web 浏览器控件的 win 表单项目。在“WebDocumentCompleted”事件中,我将
DomDocument
转换为hshtml.IHTMLDocument2
..这就是为什么我在我的项目中引用了Microsoft.mshtml
。结果:现在 @TomasLycken 建议我通过修复代码来解决这个问题。起初,我想对这个建议感到犹豫。我的代码已部署并正在运行!但是,当我进行网络搜索时,我发现 Microsoft 并不真正建议使用他们的mshtml PIA 在其开发的 Visual Studio 环境之外。
这 10 行令人反感的代码实际上是代表我们的用户进行了一些屏幕抓取数据,这些用户在几个知名门户网站上对技术主题进行研究。但是,当我测试这段 2009 年编写的代码时,它曾经操作的 DOM 现在似乎在 2016 年发生了变化。我知道令人震惊。可能不是我最聪明的代码。也许是时候退役这个函数了 - 换句话说,修复代码并重新提交。
@TomasLyken 我认为这一点是正确的。
2 - Win Forms 项目构建后脚本
上下文:所以我遇到了这个SO 上的酷后期构建技术 允许我的 WinForms 项目中的 app.config 文件进行 XDT 转换,类似于我的 Web 项目的 web.config 文件的转换方式。好吧,如果您从 SO 复制并复制到 .csproj 或 .vbproj 源文件中,那么它就可以在 OOTB 中工作。但是,一旦您将所有这些放到没有 Visual Studio 的构建服务器上,关键部分就会由于依赖于以下内容而失败:
现在这已经足够简单了,可以纠正..我刚刚将我的
C:\ 复制到 CI 服务器Program Files (x86)\MSBuild\Microsoft
目录。 但是,我应该吗?因为我有点放弃了 Visual Studio 通常支持的保留..有人可能会说 @TomasLycken 接受的答案在这个问题上仍然是正确的点,也。3 - 将所有 .NET 框架和多目标包安装到位
上面的第 1 点和第 2 点实际上是我在尝试获得第一个目标时所克服的最后事情构建要运行的作业。我的第一个构建工作是针对我在过去 8 年中创建和维护的解决方案堆栈。因此它已经经历了一些框架的考验,并且具有一些重要的纹理。我知道这并不容易。事实上,我希望通过创建一个可以构建 this .sln 的 CI 服务器,它实际上已经准备好构建我们向其提供的大多数其他解决方案。
当我第一次收到干净的“Windows 2012 R2”服务器时,它只是缺少了很多东西..我想知道我是否先安装了 Visual Studio,它是否会立即纠正其中一些东西?
以下是我必须做的事情的概要 - 但它并没有显示出解决所有问题和错误开始所涉及的痛苦和磨难。不过,也许它会对其他人有帮助。
4 - 摆脱“缺少规则集”警告 MSB3884
来自 @kevinbosman 在 此 GitHub 问题主题
5 - 让 MSTest 正确运行
You might need to install Visual Studio anyway, out of practicality
I was going to try and refute the accepted answer, posted by @TomasLycken, in the comments, but found I needed more space to talk. Even though I technically agree with what @TomasLycken has asserted, here, I'll list some of the dependencies that I found difficult to install on my CI server - and leave it to you to decide how right the accepted answer is...
1 - 'mshtml' primary interop assembly
You can see the problem I was getting in my build output at this S.O. question I created and answered. Mind you, I spent several hours figuring out how get the desired PIA registered - and it was a result of running some .exe's on the server that came from my V.Studio installation - hmmmmmm
CONTEXT: I had a win forms project that used the Web Browser control.. and in the 'WebDocumentCompleted' event, I was casting the
DomDocument
tohshtml.IHTMLDocument2
.. and that's why I had a reference toMicrosoft.mshtml
in my project.RESULT: Now @TomasLycken suggests I deal with this by fixing my code. At first, I wanted to bawk at this suggestion. My code is deployed and working! But, when I do a web search, I see that Microsoft doesn't really recommend using their mshtml PIA outside of the Visual Studio environment they developed it for.
The offending 10 lines of code was effectively doing a little screen-scraping of data on behalf of our users who do research on technical topics in several well-known web portals. But, when I tested this code, written in 2009, it appears that the DOM it once manipulated has now changed in 2016. I know shocking. Probably not my smartest bit of code. Probably time to retire this function - in other words, fix the code and recommit it.
@TomasLyken I think is right on this one.
2 - Win Forms Project post-build script
CONTEXT: So I had come across this cool post-build technique on S.O. that allows my app.config file in my WinForms project to undergo an XDT transform similar to the way my web projects' web.config files are transformed. Well, it just works OOTB, so-to-speak, if you copy from S.O. and into the .csproj or .vbproj source file. But, once you put all this onto a build server with no Visual Studio, the critical piece fails due to a dependency on:
Now this is straightfoward enough to rectify.. I just copied over to the CI server my
C:\Program Files (x86)\MSBuild\Microsoft
directory. But, should I? Since I've kinda went off the reservation of what Visual Studio normally would support.. one could argue that @TomasLycken's accepted answer is still right on this point, too.3 - Just getting all the .NET Frameworks and Multi-Targeting Packs in place
Points 1 and 2 above, were actually the last things I conquered in my attempt to get my first build job to run. And my first build job is for a solution stack that I've created and maintained over the past 8 years.. so it has weathered a few frameworks and would have some non-trivial texture to it. I knew it wouldn't be easy. In fact, I hoped by making a CI server that could build this .sln, that it would in fact be ready to build most any other solution we threw at it.
When I first received my clean "Windows 2012 R2" server, it simply had a lot of things missing.. and I'm wondering if I had installed Visual Studio first, if it would have rectified some of these things straight off?
Below is my synopsis of what I had to do - but it doesn't show the pain and suffering involved figuring it all out and the false starts. Maybe it'll help someone else, though.
4 - Getting rid of 'missing ruleset' warning MSB3884
From @kevinbosman's post on this GitHub issues thread
5 - Getting MSTest to run correctly