有什么优点和优点?为 .Net 中的每个项目创建自动构建系统有何缺点?

发布于 2024-09-27 18:00:56 字数 1575 浏览 1 评论 0原文

刚刚花费了令人沮丧的时间使用 psake 配置自动构建后,我突然想到为什么不使用我最了解的语言来创建构建器?

psake 是创建自动化构建的优秀框架。我一直遇到的麻烦是学习 powershell 来运行更复杂的任务。我确信 NAnt、msbuild 等也可以这样说。

我解决这个问题的想法是为 .Net 中的给定解决方案创建构建系统。该过程的基本结构如下:

build.bat

rem // Set the environment for msbuild.
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"

rem // Build the solution's builder.
msbuild.exe buildsolution.csproj

rem // Run the solution's builder.
BuildSolution.exe <task>

项目的 BuildSolution

一个小型控制台应用程序:

  • 引用 BuildSolution 框架。
  • 包括每个任务的方法。例如:
    • 干净
    • 构建
    • 测试
    • 提交
  • 注册可以运行的任务及其依赖项。例如:
    • Builder.RegisterTask( x => x.Clean )
    • Builder.RegisterTask( x => x.Build ).DependsOn( x => x.Clean )
    • Builder.RegisterTask( x => x.Test ).DependsOn( x => x.Build )
    • Builder.RegisterTask( x => x.Commit ).DependsOn( x => x.Test )
  • 运行构建器。例如 Builder.Execute()

测试任务

最终测试任务将调用 nunit、mstest、xunit 等,但首先构建所需的命令行。这是一个使用 .Net 而不是 PowerShell 对我来说更胜一筹的例子。

当我开发应用程序时,我遵循 ProjectName 和 ProjectName.Tests 的简单命名约定。构建系统搜索 *.Tests.dll 并将它们包含在 mstest 命令行中。

使用 .Net 应用程序构建此任务的优点是:

  • 无需学习脚本语言来查找测试 dll。
  • 使用我熟悉且功能丰富的 IDE 进行开发。
  • 使用我熟悉且功能丰富的 IDE 调试任务。

总结

除了测试任务中列出的优点之外,BuildSolution 思想还有一个优点,即项目的新开发人员可以很容易地理解和编辑构建系统。

您认为 BuildSolution 的想法有哪些缺点?

Having just spent a frustrating amount of time configuring an automated build with psake the thought occurred to me why not use the language I know best to create a builder?

psake is an excellent framework to create an automated build. The trouble I always have is learning powershell to run more complex tasks. I'm sure the same can be said for NAnt, msbuild, etc.

My idea to solve this problem is create the build system for a given solution in .Net. The basic structure of the process would be this:

build.bat

rem // Set the environment for msbuild.
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat"

rem // Build the solution's builder.
msbuild.exe buildsolution.csproj

rem // Run the solution's builder.
BuildSolution.exe <task>

Project's BuildSolution

A tiny console application that:

  • References the BuildSolution framework.
  • Includes a method for each task. eg:
    • Clean
    • Build
    • Test
    • Commit
  • Registers the tasks, and their dependencies, it can run. eg:
    • Builder.RegisterTask( x => x.Clean )
    • Builder.RegisterTask( x => x.Build ).DependsOn( x => x.Clean )
    • Builder.RegisterTask( x => x.Test ).DependsOn( x => x.Build )
    • Builder.RegisterTask( x => x.Commit ).DependsOn( x => x.Test )
  • Runs the builder. eg Builder.Execute()

Test Task

Ultimately the test task will call nunit, mstest, xunit, etc but first builds the required command line. This is an example of where using .Net instead of PowerShell is a winner for me.

When I develop my applications I follow a simple naming convention of ProjectName and ProjectName.Tests. The build system searches for *.Tests.dll and includes them in the mstest command line.

The advantages of using a .Net application to construct this task is:

  • No need to learn a scripting language to find test dlls.
  • Develop with an IDE I know well and is feature rich.
  • Debug the task with an IDE I know well and is feature rich.

Summary

In addition to the advantages listed in Test Task the BuildSolution idea has the advantage that it is arguably easy for new developers to the project to understand and edit the build system.

What cons do you see for the idea of BuildSolution?

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

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

发布评论

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

评论(1

海风掠过北极光 2024-10-04 18:00:56

据我所知,您正在谈论推出自己的解决方案。我会将其与使用其他人的现有解决方案进行比较。

优点:

  • 体积小,
  • 学习简单
  • ,调试简单
  • ,很容易引入错误修复,
  • 您不必要求获得新功能

。缺点:

  • 您重新发明了轮子(这总是会增加成本。无论是这取决于你评估的成本)
  • 你不能雇用已经了解你的构建系统的人
  • 你必须实施你自己的错误修复(是的,你会有错误),并且不能让公司外部的人照顾它,不付钱给他们
  • 你不能在网络上谷歌你的错误,因为没有人知道你有它们
  • 如果它在任意数量的团队之间共享,那么你必须把它变成一个真正的项目,有里程碑,待办事项、错误数据库等。
  • 如果您决定不将其纳入中心项目,则需要重复代码。错误修复不会在代码的不同副本之间转移。
  • 您缺少现有构建系统中的大量功能(例如,集成到您的 IDE 或其他软件、监控、内置报告、内置健康通知、实验室管理等)
  • 如果有人知道如何集成产品,您无法通过 google 进行搜索X 到你的解决方案中,而不需要做额外的工作(即编写新功能)

最终你应该尝试添加你能想到的任何你自己的优点和缺点。尤其要考虑商业角度。两种解决方案的成本均以小时/美元为单位。从长远来看,使用成本较低的方法,或使用混合方法(一种是短期的,另一种是长期的,并制定迁移计划和时间表)。

话虽这么说,我已经在多个团队中解决过不止一种类型的问题。我也从使用自己的产品转向使用别人的产品。我发现它很有价值,并且我认为在某些情况下它可能是正确的解决方案,特别是如果您将其用作短期引导程序。

From what I can tell, you're talking about rolling your own solution. I will compare this to using someone else's existing solution.

Pros:

  • It is small
  • It is simple to learn
  • It is simple to debug
  • It is easy to introduce a bug fix
  • You don't have to ask to get new features in

Cons:

  • You re-invented the wheel (this always adds cost. Whether that is as much cost is up to you to evaluate)
  • You can't hire people who already know your build system
  • You have to implement your own bug fixes (yes, you will have bugs), and can't let someone outside the company take care of it, without paying them
  • You can't google your bugs on the web, because no one knows you have them
  • If it is shared across any number of teams, then you have to turn it into a real project, with milestones, backlog, bug database, etc.
  • If you decide not to make it into a central project, you duplicate code. Bug fixes will not transfer across the different copies of the code.
  • You're missing tons of features from existing build systems (e.g. integration into your IDE or other software, monitoring, built-in reporting, built in health notifications, lab management, etc)
  • You can't google if someone knows how to integrate product X into your solution, without doing extra work on your end (i.e. coding up a new feature)

Ultimately you should try to add any of your own pros and cons that you can think of. Especially consider the business standpoint. Cost both solutions in hours/dollars. Use whichever costs less in the long run, or use a hybrid approach (one in the short term, the other in the long term, and make a plan and schedule for migration).

That being said, I've rolled my own on more than one team, for more than one type of problem. I've also migrated from rolling my own to using someone else's product. I've found it to be valuable, and I think it can be the right solution in some situations, especially if you use it as a somewhat short term bootstrap.

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