简体   繁体   English

在 MSBuild 中找不到类型或命名空间名称,但在 Visual Studio 中有效

[英]The type or namespace name could not be found in MSBuild but works in Visual Studio

I'm trying to build my multi-project solution from the dotnet CLI, but one project throws error CS0246.我正在尝试从 dotnet CLI 构建我的多项目解决方案,但一个项目引发错误 CS0246。 I have no problems building it from Visual Studio.我从 Visual Studio 构建它没有问题。 The error is encountered on line 1 in the file using the NuGet package that is causing the problem:使用导致问题的 NuGet package 在文件的第 1 行遇到错误:

using ExcelDataReader;

The error encountered:遇到的错误:

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

I run the following commands from cmd:我从 cmd 运行以下命令:

dotnet restore
dotnet clean
dotnet build

What makes building from Visual Studio different from building from the CLI?从 Visual Studio 构建与从 CLI 构建有何不同? What can I do to solve the 'missing' assembly?我能做些什么来解决“丢失”的程序集?

I got the same error error CS0246: The type or namespace name 'Polly' could not be found (are you missing a using directive or an assembly reference?) in Jenkin build, because there was version mismatch in project reference and Nuget packages config file.我得到了同样的错误error CS0246: The type or namespace name 'Polly' could not be found (are you missing a using directive or an assembly reference?)在 Jenkins 构建中,因为项目引用和 Nuget 包配置文件中存在版本不匹配.

Project reference .csproj file contains reference of 7. 2.0项目参考.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>

But Neget packages.config file contains 7. 1.0但是 Neget packages.config文件包含 7. 1.0

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

(May by someone has updated the .csproj file manually) (可能有人手动更新了.csproj文件)

To resolve this issue:要解决此问题:

  • Uninstall the library package using Nuget Package Manager.使用 Nuget Package 管理器卸载库 package。
  • Save All.保存全部。
  • Install the library package again using Nuget Package Manager.使用 Nuget Package 管理器再次安装库 package。

Verify the changes to ensure that the reference and config files have the same package reference.验证更改以确保参考和配置文件具有相同的 package 参考。

暂无
暂无

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

相关问题 错误:在Visual Studio 2013中找不到类型或命名空间名称“ApplicationUser” - Error: The type or namespace name 'ApplicationUser' could not be found in Visual Studio 2013 在 Visual Studio Code for Mac 上找不到类型或命名空间名称“System” - The type or namespace name 'System' could not be found on Visual Studio Code for Mac Visual Studio 代码:找不到类型或命名空间名称“IntPtr” - Visual Studio Code: The type or namespace name 'IntPtr' could not be found 在 Visual Studio 2017 中找不到“类型或命名空间” - 'the type or namespace could not be found' in Visual Studio 2017 Visual Studio 2017 构建到 hololens 错误 CS0246“找不到类型或命名空间名称 &#39;UnityPlayer&#39;” - Visual studio 2017 building to hololens error CS0246 "The type or namespace name 'UnityPlayer' Could not be found" Visual Studio 2013 C#找不到类型或名称空间名称IVSStatusBar - Visual Studio 2013 C# The type or namespace name IVSStatusBar could not be found MySql在Visual Studio 2012中不起作用:找不到类型或命名空间名称“MySql” - MySql doesn't work in Visual Studio 2012 : The type or namespace name 'MySql' could not be found 构建后的 Visual Studio 出现错误 CS0246:找不到类型或命名空间名称? - Visual studio after building give error CS0246: The type or namespace name could not be found? 找不到类型或命名空间名称 TSocket apache thrift C# Visual Studio 2019 - Type or namespace name TSocket could not be found apache thrift C# Visual Studio 2019 在 Visual Studio 2017 上通过 Selenium 执行 Nunit 测试时,找不到类型或命名空间名称“IWebDriver”错误 - The type or namespace name 'IWebDriver' could not be found error while executing Nunit test through Selenium on Visual Studio 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM