在构建解决方案中的任何项目之前运行的预构建事件
我编写了一个小程序来下载解决方案的所有 NuGet 包。我想设置一个预构建事件,每次构建时都会运行该程序。
但我需要它在第一个项目开始构建之前运行。我可以先查看当前正在构建的内容,然后将其放在该项目的预构建事件中,但这相当脆弱。每当我添加新项目或更新项目之间的引用时,我都必须仔细检查“第一个”建筑项目是否仍然是第一个。
所以,我真正需要的是一种在任何建筑真正开始之前做到这一点的方法。我听说过 Visual Studio 宏。但这些不是被签入的东西,所以我宁愿不使用它们(但如果这是我唯一的选择,我会使用它们)。
I have a little program I wrote to download all NuGet packages for a solution. I would like to setup a pre-build event that would run this program every time I build.
But I need it to run before the first project starts to build. I could look at what is currently building first, and put it on that project's pre-build event, but that is fairly brittle. Any time I add a new project or update references between projects, I would have to double check that the "first" building project is still the first one.
So, what I really need is a way to do this before any building really starts. I have heard of Visual Studio macros. But those are not something that gets checked in so I would prefer to not use those (but if that is my only option, I would use them).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下操作:http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild。 不幸的是
,它只能通过 MSBuild 从命令行调用。行为不同并且这些事件无法通过 IDE 获得,这似乎是一个设计缺陷。
您还可以修改基本 MSBuild 任务以包含基于特定标志/文件存在/解决方案名称的操作,但这都是邪恶的。
否则,您将很难在每个项目上进行预构建。
You could try this: http://sedodream.com/2010/10/22/MSBuildExtendingTheSolutionBuild.aspx
Unfortunately it only works called from the command line via MSBuild. Seems to be a design flaw that the behaviour is different and these events are not available via the IDE.
You could also modify your base MSBuild tasks to include the action based on a specific flag/file existence/solution name, but this is all sorts of evil.
Otherwise, you are pretty stuck with a prebuild on each project.
我从预构建事件中为任何使用 nuget 包的项目调用 nuget install 。它足够聪明,只下载尚未下载的包。
I call nuget install from the prebuild event for any project that uses nuget packages. It is smart enough to only download packages that have not already been downloaded.