MSBuild 扩展包与 MSBuild 社区任务

发布于 2024-11-25 14:33:59 字数 333 浏览 1 评论 0原文

我刚刚开始第一次制作自定义 MSBuild 脚本。我看到有两个用于扩展功能的标准选项: MSBuild Extension PackMSBuild 社区任务

我正在寻找一些指导,了解它们之间的差异,以及为什么我会使用其中一种而不是另一种,甚至两者都使用。我在 Bing 上搜索过,但只见树木不见森林。任何指导表示赞赏。

I am just starting to make custom MSBuild scripts for the first time. I see that there are two standard options for extending the features: MSBuild Extension Pack and MSBuild Community Tasks.

I am looking for some guidance about what the differences are between these, and why I would use one over the other, or even both. I have Googled on Bing, but can't see the wood for the trees. Any guidance appreciated.

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

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

发布评论

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

评论(3

蓝戈者 2024-12-02 14:33:59

我插一句,只值2美分。有几件事——首先,我不会确切地称它们为“标准”选项。两者都早于 MSBuild 4.0,内联任务和属性函数功能以及其中的许多任务几乎已经过时。我已经编写了数千行 MSBuild,并且只需要几次来自这些库的任务。

它们的优点在于它们非常模块化。您可以仅选择您需要的程序集和目标文件,并将它们签入您的代码库,而不会“卡在”整个实现中。有时,我会从一个库中挑选一项任务,并从另一个库中挑选一项任务,两者都在同一构建中。我总是更喜欢使用简单的 MSBuild 4.0 功能而不是库中的功能。我对库中的一些任务感兴趣,但这些行为根本不是我需要的,所以我自己做了一个(对于这个任务,我想到了 zip 任务,因为我想控制分组中的压缩与源文件夹不关联)。一旦您必须编写一个自定义任务,就可以很容易地在同一个程序集中滚动另一个任务。

最后,我想说,这并不是真正与库有关,而是与您对库中特定任务的非常具体的需求有关,使用您需要的东西,并且不要将您的构建与除此之外的任何东西混淆那。

I'll chime in, just 2 cents worth. Couple of things -- first of all I wouldn't exactly call them "standard" options. Both predate MSBuild 4.0 and the inline task and property function features and many of the tasks in them are pretty much obsolete. I've written thousands of lines of MSBuild and have only ever needed tasks from either of those libraries a couple times.

What is nice about them is that they are pretty modular. You can pick and choose only the assemblies and targets files you have need of and check them into your code base without getting "stuck" with the entire implementation. At times I've cherry-picked a task from one library and a task from the other, both in the same build. I always prefer using simple MSBuild 4.0 features over something in the library. I've had interest in some of the tasks in the library but the behavior wasn't at all what I needed so I whipped up my own (the zip tasks comes to mind for this one, since I wanted to control zipping in groups that didn't correlate to the source folders). Once you have to write a single custom task it becomes really easy to roll another and another, all in the same assembly.

In the end, I would say that it isn't really about the library so much as it is about the very specific need you have for particular tasks in the library, use what you need and don't tangle up your build with anything but that.

日记撕了你也走了 2024-12-02 14:33:59

我目前在工作中使用 MSBuild 社区任务。我没有接触过其他扩展,但我可以告诉一些关于这个库的事情。
优点:

  • 易于安装(MSI 安装程序)
  • 易于修改。源代码可用,并且具有 BSD 许可证,因此可以免费修改。基本上,您只需转到与任务同名的 .cs 文件,修改它,打开 .sln 文件并构建解决方案。然后,您只需将输出粘贴到 C:\Program Files\MSBuild\MsbuildTasks\
  • 如果您不想编写太多非 msbuild 代码,那么某些扩展确实非常有用。压缩很棒,对文件的正则表达式操作也很有用。
    • 我没有尝试其他,但我发现有一些有趣的任务,例如 gacutil(安装 dll 以供全局查看)、创建 IIS 目录、更改文件属性...
    • 是的,您可以使用 MSBuild 完成所有这些任务,但您需要使用大量“Exec”命令,或者在属性上使用 C# 函数,并且代码读起来会很混乱。

缺点:

  • 缺乏有用的文档(也许我搜索得不够好,但我发现的唯一帮助是下载源代码,找到适合您的任务的 .cs 文件并对其进行分析)
    • 最让我恼火的是,项目网站上没有任务的属性列表。您需要在论坛上搜索它,或者转到代码。
  • 我遇到的唯一问题是 RegexReplace 以 UTF-8 保存文件。
    我的同事编写了数千个 sql 脚本,全部采用 ANSI 编码。当我替换其中的内容并将它们传递给 SQLCMD 时,它无法解析文件,因为所有 UTF-8 文件末尾添加了一个符号(某种编码符号)。我需要转到 RegexReplace.cs,更改函数之一中的编码参数,然后编译它。所以基本上我需要创建我的叉子:)
    (两分钟的工作,一小时的向人们解释它是如何工作的)
    但是MSBuild解析UTF-8文件没有问题,所以我认为只有在使用外部工具处理文件时才可能遇到问题。

摘要:
这是一个有用的工具,易于安装和使用,它可以帮助你的代码更清晰、更容易理解,并且可以节省一些时间。我认为最大的问题是文档,但你可以在谷歌中写下任务和库的名称,并在论坛、博客和此处找到一些代码。

I am currently using MSBuild Community Tasks in my work. I didn't have contact with other extensions, but I can tell few things on this library.
Pros:

  • Easy to install (MSI Installer)
  • Easy to modify. Source is available, and it has BSD License so it's free to modify. Basically, you just go to .cs file with the same name as the task, modify it, open up .sln file and build the solution. Then you just paste the output to C:\Program Files\MSBuild\MsbuildTasks\
  • Some extensions are realy useful, if you don't wanna write to much non-msbuild code. Zipping is great, RegEx operations on files are also useful.
    • I didn't try other but I've seen there's few interesting tasks like gacutil (installing dll's to be seen globally), creating IIS directories, changing file attributes...
    • And yes, you can do all this tasks with MSBuild, but you will need to use lots of "Exec" commands, or using c# functions on your properties, and the code will be a real mess to read.

Cons:

  • lack of useful documentation (maybe I wasn't searching well enough, but only help I found is downloading source, finding .cs file for your task and analyzing it)
    • The thing that annoyed me the most, is that there's no list of attributes for tasks on the project website. You need to google it on forums, or go to the code.
  • the only problem I got is that RegexReplace saves files in UTF-8.
    My co-workers wrote like thousands of sql scripts, all encoded in ANSI. When i replaced stuff in them, and passed them to SQLCMD, then it wasn't able to parse the files, because of one sign added at the end of all UTF-8 files (some kind of encoding sign). I needed to go to RegexReplace.cs, change the encoding parameter in one of functions, and then compile it. So basically I needed to create my fork : )
    (Two minutes of work, one hour of explaining people how it works)
    But there was no problem with MSBuild parsing UTF-8 files, so I think you may encounter problems only when working with external tools to process files.

Summary:
This is an useful tool, easy to install and use, it can help to make your code a lot clearer, easier to understand, and it can save some time. I think the biggest problem is documentation, but you can just write name of task and library in google and find some code on forums, blogs and here.

日裸衫吸 2024-12-02 14:33:59

我的 2 美分 - 我遇到的情况是,我必须快速为要在普通 Windows 计算机(未安装 TFS 和 VS.NET)上运行的项目创建构建脚本。构建脚本应该执行以下操作 -

  1. 从 TFS 获取源代码
  2. 构建项目
  3. 执行单元测试
  4. 运行 FxCop、StyleCop、CodeMetrics
  5. 创建代码文档
  6. 最后,通过电子邮件发送结果

我必须超越 MSBuild 4.0,因为我想要一种简单的方法来运行上面提到的工具以及发送电子邮件。我查看了 MSBuild 社区任务和 MSBuild 扩展包。虽然我读到扩展包是一个复杂的健康包,但我仍然尝试过,但最终我使用了社区包,因为它真的很容易使用,甚至与其他包相比还可以扩展代码,即使文档较少或没有文档。在我看来,只有当您有时间了解如何使用扩展包时,扩展包才是一个选择。

My 2 cents - I was in a situation where I had to quickly create a build script for a project that was to be run on a vanilla Windows machine (without TFS and VS.NET installed). The build script was supposed to do the following -

  1. Get source from TFS
  2. Build the projects
  3. Execute Unit Tests
  4. Run FxCop, StyleCop, CodeMetrics
  5. Create Code Documentation
  6. Finally, Email results

I had to look beyond MSBuild 4.0, since I wanted an easy way to run the tools mentioned above and also send email. I looked at both MSBuild Community Tasks and also MSBuild Extension pack. While I have read that the extensions pack is a sophisticated wholesome package, I still had a try but I ended up using Community pack as it was really easy to use and even extend the code as compared to the other, EVEN with less or no documentation. Extensions Pack, in my opinion is an option only if you have time to understand how to work with it.

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