[UnityVS] Default namespace keeps resetting

Hello!

Using Visual Studio 2013 with Visual Studio 2013 Tools for Unity.

It works great, except that it keeps clearing the default namespace I am setting in the Visual Studio project settings.

  • Set default namespace in Visual Studio for projects UnityVS.Unity.CSharp, UnityVS.Unity.CSharp.Editor, and UnityVS.Unity.CSharp.Plugins.
  • Change a C# class and save.
  • Go to Unity. Unity performs a recompile.
  • Go back to Visual Studio. It says that the project has changed on disk. Reloading the project shows that I have no default namespace.

I was wondering if anyone has dealt with this before and figured out how to get the default namespace to stick.

Did you ever solve this?

Hi there,

I’m working a lot with ReSharper and it generates the namespaces itself if the project is set up correctly. Therefore I’m also very interested in this issue, as the Default Namespace of the generated projects is reset every time, so the generated namespaces are something like Assets.* which is annoying to fix every time.

@GarthSmith : Did you find any way to keep a specific default namespace?

Cheers
Christian

If anybody else likes to see the feature: Support the feature request I added for UnityVS (https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/6711722-set-the-default-namespace-of-generated-unity-proje)

Great, done :slight_smile:

Hey guys,

I’m the dev lead for the Tools for Unity.

Project specific configuration including namespace configuration is definitely planned for 2.0.

You can hack it in today with a Editor script:

using System;

using UnityEngine;
using UnityEditor;

using SyntaxTree.VisualStudio.Unity.Bridge;

[InitializeOnLoad]
public class NamespaceProjectHook
{
    private const string Namespace = "Foo.Bar";

    static NamespaceProjectHook()
    {
        ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
            content.Replace("<RootNamespace></RootNamespace>", string.Format("<RootNamespace>{0}</RootNamespace>", Namespace));
    }
}
4 Likes

Oh thats awesome thanks jbevian, congrats on the Microsoft aquire BTW

1 Like

Great to hear, thanks for your help! :slight_smile: The delegate looks like a nice way to add some more personal additions if required :wink:

1 Like