Nuget - Writing tools for Package Manager Console (custom cmdlets)

后端 未结 1 967
广开言路
广开言路 2021-01-30 12:13

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

Is there any API reference or some d

相关标签:
1条回答
  • 2021-01-30 12:40

    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.

    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.

    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.

    0 讨论(0)
提交回复
热议问题