Can you automatically insert a namespace in a visual studio snippet?

I do not think that this is possible with VS Snippets, there are only a few available functions, and they are listed at MSDN. You could, though, create a new Item Template and use the parameter $rootnamespace$, which will be replaced with the root namespace of the current project. Item templates are a really useful part of Visual Studio, and MSDN has extensive documentation on it and Visual Studio Magazine had a nice walkthrough about them.


This is possible now (2018), at least part of your's wishes, with adding this:

<Snippet>
  ...

  <Imports>
    <Import>
      <Namespace>SomeNamespace</Namespace>
    </Import>
    <Import>
      <Namespace>AnotherNamespace</Namespace>
    </Import>
  </Imports>
</Snippet>

For more info: https://github.com/dotnet/roslyn/issues/4457