Greg,

On 18 January 2016 at 22:58, Greg Keogh <gfke...@gmail.com> wrote:
> Folks, I'm looking for a way of managing snippets of code that I want to
> include in multiple unrelated projects. I want them to behave like little
> Nuget packages of source code, so when I update snippets in one project they
> will be recognised as out-dated when I open other projects using them.

On 19 January 2016 at 07:19, David Smith <dav...@nzcity.co.nz> wrote:
> Could you use your version control software to do this?
>
> SVN has externals & Git has  submodules.  Perhaps these mechanisms could do
> what you want?

On 19 January 2016 at 09:17, Greg Keogh <gfke...@gmail.com> wrote:
> Hi guys, I'm pretty sure I want this "thing" to work at the source code
> level, not at the binary reference level. I said I could put all the
> snippets in DLLs, but I would finish up with dozens of them, each contain
> maybe only 10 lines of code (I have my own local Nuget package source for
> testing).
>
> This mention of SVN externals and Git modules sounds like it's heading in
> the right direction. I personally avoid Git (that's another story), but I a
> quick search about Mercurial "externals" or "subreprositories" shows a few
> confusing overviews that might clarify it if works the way I want. I'll
> report if I find anything useful. It'd be great if you could something like
> this, but this is where I suspect a VS extensions would be required to
> implement it.
>
> #region Snippet: My Snazzy Snippet
> :
> // code would be "included" here
> :
> #endregion

The subrepos/externals feature of your VCS should do mostly what you
want, but it will not splice snippets into existing files as in your
example. It will check out whole files. As whole files, your snippets
will need to be complete C# source files, which means classes (whole
or partial, but classes nonetheless), not isolated methods.

To splice snippets into existing sources, you could use T4 "@include",
or you could program msbuild to use a preprocessor. Either way, you
can forget about reliable IntelliSense. Personally, I would not go
down this splicing route unless both Visual Studio and csc.exe had
first-class support for it. For now, snippet files with static partial
classes that you can add "As Link" from the subrepo should be the
simplest, safest way.

--
Thomas Koster

Reply via email to