在 NAnt 中,我可以创建 VS 项目中列出的文件的文件集吗?
我正在重写我们的 NAnt 构建脚本,使它们更干净、更简单,并且用途更通用。
我们的构建过程中的步骤之一是将某些文件打包到 zip 文件中。 在我们创建文件集
有很多包含的文件类型,试图捕获项目中可能存在的所有内容。 当我们想要在项目中包含非标准文件类型时,这有时会引起问题。
我希望我能找到一种方法来创建 文件集
基于 Visual Studio 项目文件 (.csproj) 中列出的文件(以及文件的子集)。 然后我可以在 zip
中使用此文件集 任务。 我还没有找到任何可以自动执行此操作的内容(尽管现已弃用的 NAntContrib 中的 SLiNgshoT
任务看起来有点有希望)。
我开始尝试手动执行此操作,但陷入困境。 我有一个从解决方案中获取项目的目标(使用 regex
),然后尝试使用 xmlpeek
(使用 XPath 查询 /n:Project/n:ItemGroup/n:Content/@Include
)。 这里的问题是 xmlpeek
不返回每个值,仅返回第一个值。 而且,即使它确实返回了每个值,我也不确定如何将其放入 文件集
从这里。
有什么办法可以挽救这种思维轨迹吗? 我可以通过自定义 NAnt 任务完成我想要的任务吗(我不希望每个项目都依赖于自定义任务)? 有没有一些我没有找到的内置方法可以做到这一点?
如果我的目标或方法不清楚,请随时在评论中提问。
谢谢!
更新:澄清一下,我的观点是让整个过程更加无缝。 虽然我可以轻松地将所有 .xml 文件添加到包中,但这通常会得到位于同一文件夹中但实际上并不是项目一部分的 .xml 文件。 当我已经有了项目使用的文件列表(甚至在内容和其他类型之间分开)时,不使用该信息似乎很遗憾。 最终,任何人都不应该接触构建文件来更改包中包含的内容。 对我来说这似乎并不是一个白日梦......
I'm rewriting our NAnt build scripts to make them cleaner and simpler, as well as more general purpose.
One of the steps in our build process is to package certain files into a zip file. Before we had created a fileset
with lots of included file types, trying to catch everything that might be in the project. This occasionally caused problems when we wanted to include a non-standard file type with the project.
I was hoping that I could find a way to create a fileset
based on the files (and, also, a subset of the files) listed in the Visual Studio project file (.csproj). I could then use this fileset in a zip
task. I haven't found anything that does this automatically (though the now-deprecated SLiNgshoT
task in NAntContrib looked a little promising).
I started down the path of trying to do this manually, but have gotten stuck. I have a target that gets the project from the solution (using regex
), then tries to get each Content file in the project using xmlpeek
(with the XPath query /n:Project/n:ItemGroup/n:Content/@Include
). The problem here is that xmlpeek
doesn't return every value, just the first. And, even if it did return every value, I'm not sure how I'd get it into a fileset
from here.
Is there any way to salvage this track of thinking? Can I accomplish what I want with a custom NAnt task (I'd prefer not to have every project dependent on a custom task)? Is there some built-in way to do this that I'm not finding?
Please feel free to ask questions in the comments if something about my goal or method isn't clear.
Thanks!
UPDATE: To clarify, my point in all of this is to make the whole process much more seamless. While I can easily add all .xml files to a package, this often gets .xml files that live in the same folder but aren't really part of the project. When I already have a list of the files that the project uses (separated out between Content and other types, even), it seems a shame not to use that information. Ultimately, no one should have to touch the build file to change what gets included in a package. It doesn't seem like too much of a pipe dream to me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅此相关问题。 microsoft.build.buildengine 接口应该可以让您更好地访问所需的信息,但不幸的是我认为您必须构建自定义任务。
但我认为解析项目文件以生成在其他地方使用的文件集......将所有内容都放在构建脚本中有点太多。 既然您似乎想重用它,我认为依赖自定义任务并不比任何其他形式的重用更糟糕(即使您可以在现有的 Nant 任务中完成这一切,您也可以这样做)仍然需要让每个项目以某种方式继承该流程)。
See this related question. The microsoft.build.buildengine interface should let you get much better access to the information you need, but unfortunately I think you would have to build a custom task.
But I think that parsing a project file to generate a fileset that is used elsewhere is ... a bit much to put all inside your build script. And since you seem to want to re-use this, I don't think that depending on a custom task is any worse than any other form of re-use (even if you can do it all in existing Nant tasks, you'd still need to have every project inherit that process somehow).
至于阅读您的项目文件。 我以前做过类似的事情。 我最终只是编写了一个程序来读取项目文件并通过项目构建文件构建自定义项目。
但是我正在尝试编译我的代码库。 看来您正试图将其压缩。
考虑到 Zip 任务允许您在其中运行多个文件集,您可以创建一些通用文件集,然后相当轻松地更新您的特定文件集。
所以你可以有这样的东西:
然后在你的 zip 目标中输入:
现在如果你想要项目细节。 您还可以做另一件事。 如果您使用的是 VS2005 或更高版本,请在 T4 上搜索。 它是一个用于创建插件的模板框架,允许您在执行某些操作时生成额外的文件。 有点像当你做一个类图或有一个 XSD 时(它得到它的代码隐藏文件,它是这样完成的)。
在我参与过的大多数项目中,我们都会为每个项目维护一个构建文件并使其保持最新。 由于我们有通用文件集,这是一个开始,因此我们只需要更新晦涩难懂的内容的文件。
希望有帮助。 如果您能提供更多详细信息,我也许可以提供更多帮助。
As far as reading your project files. I've done something like this before. I ended up just writing a program that read the project files and built a custom project by project build file.
However I was trying to compile my code base. Looks like you are trying to just zip it.
Considering that the Zip task would allow you to run multiple filesets into it you could create some generic filesets and then just update for your specific ones rather easily.
So you could have something like this:
Then in your zip target just put:
Now if you wanted project specifics. There is one other thing you could do. If you are using VS2005 or greater search on T4. It's a template framework for creating plugins that allow you have extra files generated when you do something. Kind of like when you do a class diagram or have a XSD (and it gets it's code behind file, it's done this way).
In most projects that I've worked on we maintain a build file for each project and just keep it up to date. Since we have the generic filesets that's a start so we only really need to update the file for the obscure stuff.
Hope that helps. If you could provide a little more detail I might be able to help further.
我喜欢乔希想法的第一部分。
编写一个小型控制台应用程序以从 .csproj 中提取文件(因为其中只有 XML)并将列表写入文件。
我将使用 7-zip 使用您生成的列表创建存档,而不是 NAnt 的 zip 任务在上一步中:(
我在这里创建一个自解压存档)
希望有帮助,
-jason
I like the first part of Josh's idea.
Write a small console app to pull the files from the .csproj (since it's just XML in there) and write the list out to a file.
Instead of NAnt's zip task, I would use 7-zip to create the archive with the list you generated in the previous step:
(I'm creating a self extracting archive here)
Hope that helps,
-jason