how to change namespace of entire project?

前端 未结 11 625
梦如初夏
梦如初夏 2020-12-22 22:30

I\'m modifying demo application from this article: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

I need to update all files to use my namespace, for example

相关标签:
11条回答
  • 2020-12-22 22:41

    Ctrl+Shift+H not the real solution.

    You can use Resharper to change your all namespace definitions in your solution. This is the best way I tried before.

    https://www.jetbrains.com/resharper/features/code_refactoring.html

    0 讨论(0)
  • 2020-12-22 22:50

    Just right click the solution, go to properties, change "default namespace" under 'Application' section.

    0 讨论(0)
  • 2020-12-22 22:53

    Go to someplace the namespace is declared in one of your files. Put the cursor on the part of the namespace you want to change, and press F2. This should rename the namespace in every file. At least, it worked in my little demo project I created to test this answer!

    Depending on your VS version, the shortcut might also be Ctrl-R,Ctrl-R.

    0 讨论(0)
  • 2020-12-22 22:53

    I tried everything but I found a solution which really works. It creates independed solution with a new namespace name an so on.

    1. In main form find namespace name -> right click -> Refactor -> Rename and select a new name. Check all boxes and click OK.

    2. In the solution explorer rename solution name to a new name.

    3. In the solution explorer rename project name to a new name.

    4. Close VS and rename folder (in total commander for example) in the solution folder to a new name.

    5. In .sln file rename old name to a new name.

    6. Delete old .suo files (hidden)

    7. Start VS and load project

    8. Project -> properties -> change Assembly name and default namespace to a new name.

    0 讨论(0)
  • 2020-12-22 22:56

    When I wanted to change namespace and the solution name I did as follows:
    1) changed the namespace by selecting it and renaming it and I did the same with solution name
    2) clicked on the light bulb and renamed all the instances of old namespace
    3) removed all the projects from the solution
    4) closed the visual studio
    5) renamed all the projects in windows explorer
    6) opened visual studio and added all the projects again
    7) rename namespaces in all projects in their properties
    8) removed bin folder (from all projects)
    9) build the project again

    That worked for me without any problems and my project had as well source control. All was fine after pushing those changes to the remote.

    0 讨论(0)
  • 2020-12-22 22:58

    I have gone through the folder structure with a tool called BareGrep to ensure I have got all of the namespace changes. Its a free tool that will allow you to search over the files in a specified file structure.

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