如何使用 MSBuild 将另一个项目导出为 Visual Studio 模板项目?

发布于 2024-08-04 20:05:22 字数 572 浏览 6 评论 0原文

这就是我想要实现的目标。我有许多 C# 和 VB 项目,我希望将它们导出为模板项目,作为自动构建过程的一部分。导出模板很容易以交互方式完成,但我需要将其作为自动构建过程的一部分。此外,模板项目实际上必须在导出之前构建,以便保证最终用户使用模板时它们能够编译。 [我知道模板项目通常不会编译,但我已经解决了这个问题,因此就这个问题而言,我们可以认为模板项目将成功编译]。

我计划使用 MSBuild 社区任务来压缩我的最终导出模板项目。但是,我无法将此操作放置在模板项目本身中,因为该操作随后将作为模板的一部分导出,而这不是我想要发生的情况。

所以我的想法是,我可以创建一个新的单独的 MSBuild 项目,该项目检查其他模板项目,发现其中包含哪些文件,添加预定义的 MyTemplate.vstemplate 文件,压缩这些文件和“walla”,这是我导出的模板。

到目前为止,一切都很好。唯一的问题是,我是一个完全的 MSBuild 菜鸟,而且我在入门时遇到了困难。请,我很重视有关如何实现这一目标的任何建议。

我痛苦地意识到这几乎是一个“为我做我的工作”类型的问题,我的辩护是(a)这实际上不是我的工作,(b)我尝试做我的 MSBuild 作业,灵感只是不流动。

Here's what I'm trying to achieve. I have a number of projects in C# and VB which I wish to export as template projects as part of my automated build process. Exporting templates is easy to do interactively, but I need to do it as part of my automated build process. Further, the template projects must actually be built prior to exporting them, so that they are guaranteed to compile when the end user uses the template. [I know that template projects don't usually compile, but I have solved that problem, so for the purposes of this question, we can take it as read that the template projects will compile successfully].

I plan to use the MSBuild Community Tasks to zip up my final exported template project. However, I can't place this action in the template project itself, because that action would then be exported as part of the template and that's not what I want to happen.

So my thought is that I could create a new seperate MSBuild project, that examines the other template projects, discovers what files are in them, adds a predefined MyTemplate.vstemplate file, zips up those files and "walla", there's my exported template.

So far so good. The only problem is, I'm a complete MSBuild noob and I'm having trouble getting started. Please, I would value any suggestions on how to accomplish this.

I'm painfully aware that this is almost a "do my job for me" type of question, my defense is that (a) it's not actually my job and (b) I've tried to do my MSBuild homework and the inspiration just isn't flowing.

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

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

发布评论

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

评论(1

执笔绘流年 2024-08-11 20:05:22

除了“为您做”()之外,我向您展示一下其他地方是如何完成的怎么样?我自己也在那边做了同样的事情:

http://github.com/AArnott/dotnetopenid/commits< /a>

具体而言,projecttemplates/WebFormsRelyingParty Web 项目由 build.proj 文件的 BuildProjectTemplates 目标转换为项目模板。

我的策略是拥有一个我所从事的普通(可编译)C# Web 项目。我在该文件夹中还有一个 .vstemplate 文件,该文件添加到项目中,但已存在,因此我可以进行更改。然后在构建过程中,我让 MSBuild 构建网站,将结果(不包括网站构建的大部分产品)复制到临时位置。在复制过程中,我有一个自定义 MSBuild 任务,它将所有源文件中的 Web 应用程序名称替换为 $safeprojectname$,因为这是 VS 项目模板创建者所做的事情。它还复制图标以用于模板。最后,它将其压缩并将 .zip 文件放入我的输出目录中。

Short of "doing it for you" (), how about I show you how it's done elsewhere? I just did the same thing myself over yonder:

http://github.com/AArnott/dotnetopenid/commits

Specifically, the projecttemplates/WebFormsRelyingParty web project is transformed into a project template by the build.proj file's BuildProjectTemplates target.

My strategy is to have an ordinary (compilable) C# web project that I work on. I also have a .vstemplate file in that folder that's not added to the project, but is around so I can make changes. Then during my build, I have MSBuild build the web site, copy the result (excluding most of the products of the build of the web site) to a temporary location. During the copy, I have a custom MSBuild task that replaces my web application name with $safeprojectname$ in all the source files, since this is what the VS project template creator does. It also copies in the icon to use for the template. Finally, it zips it up and puts the .zip file in my output directory.

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