[英]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:要解决此问题:
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.