【问题标题】:Resharper keeps complaining that a namespace doesn't correspond to file location even though it doesResharper 一直抱怨命名空间与文件位置不对应,即使它确实如此
【发布时间】:2013-04-24 01:53:23
【问题描述】:

我正在开发一个 WCF 项目。该项目的名称曾经是ServiceTemplate,我决定将其更改为更具指示性的名称。我根据以下步骤完成了重命名项目的一些痛苦的工作:

  • 根据新项目名称更改命名空间。此步骤预计会导致 Resharper 抱怨命名空间与其文件位置不对应,并建议将命名空间更改为“ServiceTemplate.Something”。我忽略了警告,因为它应该稍后消失。

  • 使用 find-and-replace 替换整个解决方案中所有出现的“ServiceTemplate”。

  • 关闭解决方案。

  • 重命名 ServiceTemplate 文件夹和 ServiceTemplate.csproj 文件。

  • 用记事本打开 sln 文件,重复查找和替换的丑陋过程,以替换该文件中所有出现的“ServiceTemplate”。

即使经过所有这些步骤,Resharper 仍然抱怨命名空间与文件位置不对应。奇怪的是,Resharper 仍然建议将命名空间更改为“ServiceTemplate.Something”,即使字符串“ServiceTemplate”不在解决方案中的任何位置,无论是文件夹/文件名还是文件内容。

什么可能导致了问题,我该如何解决?

【问题讨论】:

    标签: c# visual-studio resharper


    【解决方案1】:

    您还需要确保更改项目属性中的默认命名空间,在更改程序集名称的位置旁边。 ReSharper 在决定文件中的命名空间应该是什么时也会使用它。

    【讨论】:

      【解决方案2】:

      您需要修改 .vbproj 或 .csproj 文件中的属性\元素 。正如@citizenmatt所建议的那样。

      建议更改:

      <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
       <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
        <ProjectGuid>{14E9B75E-02B5-4371-912F-674B7E199796}</ProjectGuid>
        <OutputType>Library</OutputType>
        <AppDesignerFolder>Properties</AppDesignerFolder>
        <RootNamespace>My.Default.Namespace</RootNamespace> //<-- Change this
        <AssemblyName>My.Assembly.Name</AssemblyName>
        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
        <FileAlignment>512</FileAlignment>
      </PropertyGroup>
      

      【讨论】:

        猜你喜欢
        • 2012-03-12
        • 1970-01-01
        • 2019-02-05
        • 1970-01-01
        • 1970-01-01
        • 2020-06-15
        • 1970-01-01
        • 2018-01-19
        • 1970-01-01
        相关资源
        最近更新 更多