【问题标题】:The type or namespace name could not be found in MSBuild but works in Visual Studio在 MSBuild 中找不到类型或命名空间名称,但在 Visual Studio 中有效
【发布时间】:2020-06-08 07:55:37
【问题描述】:

我正在尝试从 dotnet CLI 构建我的多项目解决方案,但一个项目引发了错误 CS0246。我从 Visual Studio 构建它没有问题。使用导致问题的 NuGet 包在文件的第 1 行遇到错误:

using ExcelDataReader;

遇到的错误:

error CS0246: The type or namespace name 'ExcelDataReader' could not be found (are you missing a using directive or an assembly reference?)

我从 cmd 运行以下命令:

dotnet restore
dotnet clean
dotnet build

从 Visual Studio 构建与从 CLI 构建有何不同?我可以做些什么来解决“丢失”的程序集?

【问题讨论】:

    标签: c# .net msbuild exceldatareader


    【解决方案1】:

    我在 Jenkins 构建中遇到了同样的错误 error CS0246: The type or namespace name 'Polly' could not be found (are you missing a using directive or an assembly reference?),因为项目参考和 Nuget 包配置文件中存在版本不匹配。

    项目参考.csproj 文件包含7.2.0

    的参考
    <Reference Include="Polly, Version=7.0.0.0, Culture=neutral, PublicKeyToken=c8a3ffc3f8f825cc, processorArchitecture=MSIL">
         <HintPath>..\packages\Polly.7.2.0\lib\net472\Polly.dll</HintPath>
    </Reference>
    

    但 Neget packages.config 文件包含 7.1.0

    <package id="Polly" version="7.1.0" targetFramework="net472" />
    

    (可能有人手动更新了.csproj文件)

    要解决此问题:

    • 使用 Nuget 包管理器卸载库包。
    • 全部保存。
    • 使用 Nuget 包管理器再次安装库包。

    验证更改以确保引用和配置文件具有相同的包引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-23
      • 2013-11-16
      • 1970-01-01
      • 2021-07-17
      相关资源
      最近更新 更多