Nuget - 包管理器控制台的编写工具(自定义 cmdlet) [英] Nuget - Writing tools for Package Manager Console (custom cmdlets)

查看:19
本文介绍了Nuget - 包管理器控制台的编写工具(自定义 cmdlet)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 nuget 包管理器,我真的很喜欢 mvc-scaffold 扩展.我想为我的项目编写类似的工具.

I've installed nuget package manager and I really love mvc-scaffold extension. I would like to write similar tool for my projects.

是否有任何 API 参考或一些我可以学习的 nuget 文档?TIA 的任何建议.

Is there any API reference or some documentation for nuget I can learn from ? TIA for any suggestions.

问题已经回答"(再一次),这里有一些可能会有所帮助的链接:

Question is already 'answered' (thx one more time), here are some links that can be helpful:

  • http://nuget.codeplex.com/releases/view/59864 - package explorer (download + see what it's inside the package - thank God for comments in mvc scaffolding ps scripts :))
  • http://channel9.msdn.com/Series/mvcConf/mvcConf-2-Steve-Sanderson-MvcScaffolding - video from mvcConf2
  • and of course Steve Sanderson's blog : http://blog.stevensanderson.com/

推荐答案

我编写了您在问题中提到的当前版本的 MvcScaffolding.以下是将 PowerShell cmdlet 添加到包管理器控制台的方法:

I wrote the current version of MvcScaffolding that you mention in your question. Here's how it adds PowerShell cmdlets to the Package Manager Console:

  • Cmdlets are written in C# and compiled into a .NET assembly (see http://msdn.microsoft.com/en-us/magazine/cc163293.aspx)
  • The .NET assembly is included in MvcScaffolding's "tools" folder (see http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#From_a_convention_based_working_directory)
  • MvcScaffolding also contains an init.ps1 file that NuGet runs each time you open a solution containing it (also described at http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Automatically_Running_PowerShell_Scripts_During_Package_Installation_and_Removal). This script uses the PowerShell "Import-Module" command to import the cmdlets from the .NET assembly, making them available in the console.

请注意,实际上没有必要用 C# 编写 cmdlet 并调用 Import-Module.更简单的替代方法是在 PowerShell 中编写它们(请参阅 http://technet.microsoft.com/en-us/magazine/ff677563.aspx)并在 NuGet 包的 init.ps1 文件中内联定义它们.

Note that it's not actually necessary to write your cmdlets in C# and call Import-Module. A simpler alternative is to write them in PowerShell (see http://technet.microsoft.com/en-us/magazine/ff677563.aspx) and define them inline in your NuGet package's init.ps1 file.

或者,如果您的问题是关于如何将自定义脚手架添加到 MvcScaffolding(例如,您可以说Scaffold MyCustomThing -somecustomparams"),然后使用命令Scaffold CustomScaffolder MyCustomThing",然后编辑 PS1/T4 文件出现在您的 CodeTemplates/Scaffolders 文件夹中.我会尽快在博客上详细介绍这一点.

Or, if your question is about how to add custom scaffolders to MvcScaffolding (e.g., so you can say "Scaffold MyCustomThing -somecustomparams"), then use the command "Scaffold CustomScaffolder MyCustomThing", and then edit the PS1/T4 files that appear in your CodeTemplates/Scaffolders folder. I'll blog more details about this soon.

这篇关于Nuget - 包管理器控制台的编写工具(自定义 cmdlet)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆