how to change namespace of entire project?

2019-01-30 07:07发布

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 now file located here:

MySolution\MyApp\DemoApp\ViewModel\MainWindowViewModel.cs

is using such namespace:

namespace DemoApp.ViewModel
{
/// <summary>
/// The ViewModel for the application's main window.
/// </summary>
public class MainWindowViewModel : WorkspaceViewModel

I need to move file here (remove DemoApp folder):

MySolution\MyApp\ViewModel\MainWindowViewModel.cs

and also to use right namespace:

namespace MyApp.ViewModel
{
....

how to do that in visual studio 2010?

Update ok here is possible duplicate Change Project Namespace in Visual Studio Now I know how to change the namespace of the project, but how to move files on the file system? (get rid of "DemoApp" folder)

8条回答
男人必须洒脱
2楼-- · 2019-01-30 07:47

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.

查看更多
爷的心禁止访问
3楼-- · 2019-01-30 07:49

I know its quite late but for anyone looking to do it from now on, I hope this answer proves of some help. If you have CodeRush Express (free version, and a 'must have') installed, it offers a simple way to change a project wide namespace. You just place your cursor on the namespace that you want to change and it shall display a smart tag (a little blue box) underneath namespace string. You can either click that box or press Ctrl + keys to see the Rename option. Select it and then type in the new name for the project wide namespace, click Apply and select what places in your project you'd want it to change, in the new dialog and OK it. Done! :-)

查看更多
Evening l夕情丶
4楼-- · 2019-01-30 07:55

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

查看更多
爷的心禁止访问
5楼-- · 2019-01-30 08:00

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.

查看更多
Juvenile、少年°
6楼-- · 2019-01-30 08:02

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.

查看更多
做个烂人
7楼-- · 2019-01-30 08:02

You can use CTRL+R, CTRL+R or for complex namespace changes use this tool https://marketplace.visualstudio.com/items?itemName=vs-publisher-599079.FixNamespace

查看更多
登录 后发表回答