简体   繁体   English

Visual Studio 2010重命名项目并使Namespacing对应

[英]Visual Studio 2010 Rename Project and cause Namespacing to correspond

In Visual Studio 2010 I have an ASP.NET MVC 3 project called blahblah. 在Visual Studio 2010中,我有一个名为blahblah的ASP.NET MVC 3项目。 As such, all the code within this project is namespaced as blahblah.Controllers, blahblah.Configuration etc. 因此,此项目中的所有代码都被命名为blahblah.Controllers,blahblah.Configuration等。

I want to be able to rename the project to blahblah.Web. 我希望能够将项目重命名为blahblah.Web。 Now I know I can just right click on the project and go to rename, but if I do this, none of the namespacing matches anymore. 现在我知道我可以右键单击该项目并重命名,但是如果我这样做,那么命名空间就不再匹配了。

I would like some way to convert all namespacing so that it is relative to the new project name. 我想要一些方法来转换所有命名空间,以便它相对于新项目名称。 blahblah.Web.Controllers, blahblah.Web.Configuration, etc. blahblah.Web.Controllers,blahblah.Web.Configuration等

Is there an easy way to do this? 是否有捷径可寻?

Yes, use ReSharper's 'Refactor' menu and select 'Adjust Namespaces'. 是的,使用ReSharper的'Refactor'菜单并选择'Adjust Namespaces'。 http://www.jetbrains.com/resharper/webhelp/Refactorings__Adjust_Namespaces.html http://www.jetbrains.com/resharper/webhelp/Refactorings__Adjust_Namespaces.html

The easiest way is to use a Replace in Files or CTRL + SHIFT + H . 最简单的方法是使用替换文件CTRL + SHIFT + H.

Search for the full previous namespace eg namespace blahblah.Web.Controllers and replace with the new namespace eg namespace blahblah.Web.Configuration . 搜索完整的先前命名空间,例如namespace blahblah.Web.Controllers并用新命名namespace blahblah.Web.Configuration替换,例如namespace blahblah.Web.Configuration

Also, remember the change the default namespace in the project properties so that any new files get created in the correct namespace. 另外,请记住更改项目属性中默认命名空间 ,以便在正确的命名空间中创建任何新文件。

Without third party add-ons: Edit > Find and Replace > Replace in Files 没有第三方加载项:编辑>查找和替换>替换文件

Find what: namespace blahblah 找到什么:namespace blahblah
Replace with: namespace blahblah.Web 替换为:namespace blahblah.Web

Click on Replace All. 单击“全部替换”。

Using Find and Replace 使用查找和替换

Do a search for "using blahblah." 搜索“使用blahblah”。 and replace it with "using blahblah.Web." 并用“使用blahblah.Web”替换它。

Ignore the quotation marks there just to show the string to use. 忽略那里的引号只是为了显示要使用的字符串。 That should do it easily enough. 这应该很容易做到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM