propose new feature: add code snippet for nuget package during installation

Apr 12, 2011 at 11:57 PM

Following a nuget package installation, I thought of a cool feature that would be relatively easy to include with each installation and optional for those that wanted to include.

Basically the feature would allow developers to include with each package installation, a snippet.xml file which includes "code blocks" for their package thats installed.  These "code blocks" are simple examples of how to quickly and easily add a section of code for the reference library(s) that were just added.

The snippet.xml file (propose naming to: nuget_[packagename].xml) would be installed by default and an optional feature of nuget.

Example snippet.xml format.

<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>
                My Snippet
            </Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.Windows.Forms.dll</Assembly>
                </Reference>
            </References>
            <Code Language="VB">
                <![CDATA[MessageBox.Show("Hello World")]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>
Apr 13, 2011 at 8:01 AM

There were a couple earlier threads on this topic:

And related blog posts:

Those solutions rely on some powershell script to install the snippets. Conceivable at some point we could turn this into a 'native' feature that NuGet understands directly.

Apr 13, 2011 at 7:25 PM

Thank you. I like GeertvanHorrik solution a lot.

I wonder if it makes sense to create a simple "codeblocks" nuget package that just installs snippets.  it could have some intelligence to it that checks for dependent packages installed first, allows those to be installed, while greying out the others?

These snippets would not be installed or "owned" by the specific nuget package owner but rather a "collection" of snippets for all the various packages. 

If this seems useful, we/I could create a nuget package that does just this and others could just contribute samples to include. 

Basically a nuget package of snippets for nuget packages...

-todd

Apr 14, 2011 at 12:30 AM

We can experiment with that idea. Though my concern is that the single package approach won't scale well compared to an approach where each package carries its own embedded snippets.

What do others think?

Apr 14, 2011 at 2:15 AM

Embedded or somelibrary.snippet (like somelibrary.sample).

Keep it simple and separate (a new KISS). ;)
____
Rob
"Be passionate in all you do"

http://devlicio.us/blogs/rob_reynolds
http://ferventcoder.com
http://twitter.com/ferventcoder