ReSharper:命名空间与文件位置不对应
我重命名了一个文件夹并更新了命名空间声明,但 ReSharper 6 声称命名空间应该反映重命名之前的情况。文件位置数据存储在哪里?
I renamed a folder and updated my namespace declarations, but ReSharper 6 claims that the namespace should be a reflection of how it was before the rename. Where is it storing the file location data?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我也遇到了文件夹/命名空间的问题,上述步骤都没有解决它。
就我而言,我必须在 Visual Studio 中执行此操作:
这为我解决了 ReSharper 问题,我能够像平常一样调整命名空间。
I also had this problem with a folder/namespace and none of the above steps fixed it.
In my case I had to do this in Visual Studio:
This fixed the ReSharper issue for me and I was able to adjust namespaces as normal.
根命名空间需要更改如下。
Root namespace is needed to be changed as following.
我在 VS 2019 和 16.5.2 中使用 Resharper 2019.3.2,也遇到了类似的问题。
开发时,我首先在单个项目中计算出命名空间层次结构,然后将该项目拆分为单独的类库。在第一阶段,总是让子目录对应于命名空间是很方便的。
例如,我的原型 MeshTools.dll 项目当前包含:
上述答案均假设每个项目有一个命名空间。手动重命名目录可能会使 Resharper 感到困惑,这可以通过将 .csproj 文件中的默认程序集设置为正确的命名空间来修复。谢谢你的提示。
然而,就我而言,我在一个项目中有多个命名空间,解决方案目录中的每个命名空间都对应于一个真实的目录。当重命名出现问题时,设置默认程序集“Meshtools”不会影响 HeightField 和 VectorTools 的 ReSharper 行为。
我用谷歌搜索了这个问题,并找到了 https://www.jetbrains.com/help/ resharper/Refactorings__Adjust_Namespaces.html#
事实证明,解决方案目录 -> 上有一个右键单击选项。属性。您将找到一个选项来决定解决方案目录是否是名称空间提供商。当出现问题时,Visual studio 会将该字段重置为 False。将其设置回 True,Resharper 将在需要时正确重构命名空间或文件位置。
I use Resharper 2019.3.2 in VS 2019 vs 16.5.2 and I had similar issues.
When developing, I first work out my namespace hierarchy in a single project, then split the project in seperate class libraries. In the first stage, it is convenient to always let the subdirectory correspond to the namespace.
For example, my prototype MeshTools.dll project currently contains:
The above answers all assume one single namespace per project. Renaming directories manually may confuse Resharper and that can be repaired by setting the default assembly in the .csproj file to the proper namespace. Thanks for the tip.
However in my case, I have several namespaces in a single project, with each namespace in a Solution directory corresponding to a real directory. Setting the default assembly "Meshtools" does not affect ReSharper behaviour for HeightField and VectorTools, when things have gone wrong with the renaming.
I googled this issue and came by https://www.jetbrains.com/help/resharper/Refactorings__Adjust_Namespaces.html#
It turns out there is a right-click option on a Solution Directory -> Properties. You will find an option to decide, if the Solution Directory is a NameSpace provider or not. When something has gone wrong, Visual studio will reset the field to False. Set it back to True and Resharper will correctly refactor namespace or file location when needed..
如果您使用的是 JetBrains Rider,请转到解决方案资源管理器并右键单击 csproj 文件,然后右键单击上下文菜单中的属性。在我的例子中,程序集名称已经更新,但“根命名空间”没有更新,更新根命名空间允许 JetBrains 自动更新所有命名空间。
If you're using JetBrains Rider, go to the Solution Explorer and right click on the csproj file, then properties in the context menu. In my case the Assembly Name was already updated but "Root Namespace" wasn't, updating Root Namespace allowed JetBrains to automatically update all namespaces.
检查以确保您的程序集名称与新的命名空间匹配。如果您已更改文件夹结构以匹配新的命名空间,则在更新项目属性之前,您可能仍会看到 ReSharper 警报。
Check to make sure your assembly name matches your new namespace. If you've changed your folder structure to match your new namespace, you may still see the ReSharper alert until you update the project properties.
作为 delliottg 评论说,在 Visual Studio 中,转到
Project
>[项目名称]属性
>应用程序
并更改“程序集名称”以及“默认命名空间”。
As delliottg's comment says, in Visual Studio, go to
Project
>[project name] Properties
>Application
and change "Assembly name" as well as "Default namespace".