简体   繁体   English

为什么 Microsoft 分析器找不到 Microsoft.CodeAnalysis?

[英]Why can't Microsoft analyzers find Microsoft.CodeAnalysis?

I'm trying to add Microsoft.CodeAnalysis.FXCopAnalyzers (latest stable version) to my ASP.NET project.我正在尝试将Microsoft.CodeAnalysis.FXCopAnalyzers (最新稳定版本)添加到我的 ASP.NET 项目中。 When I install it via NuGet, I get a ton of errors like:当我通过 NuGet 安装它时,我收到了大量错误,例如:

An instance of analyzer Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.AbstractTypesShouldNotHaveConstructorsAnalyzer cannot be created from \\packages\\Microsoft.CodeQuality.Analyzers.2.6.3\\analyzers\\dotnet\\cs\\Microsoft.CodeQuality.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.无法从 \\packages\\Microsoft.CodeQuality.Analyzers.2.6.3\\analyzers\\dotnet\\cs\\Microsoft.CodeQuality.Analyzers.dll 创建分析器 Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.AbstractTypesShouldNotHaveConstructorsAnalyzer 的实例:无法加载文件或程序集“Microsoft.CodeAnalysis,版本=2.6.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 The system cannot find the file specified.. An instance of analyzer Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.AvoidEmptyInterfacesAnalyzer cannot be created from \\packages\\Microsoft.CodeQuality.Analyzers.2.6.3\\analyzers\\dotnet\\cs\\Microsoft.CodeQuality.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.系统找不到指定的文件。无法从 \\packages\\Microsoft.CodeQuality.Analyzers.2.6.3\\analyzers\\dotnet\\cs\\Microsoft.CodeQuality.Analyzers 创建分析器 Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.AvoidEmptyInterfacesAnalyzer 的实例.dll:无法加载文件或程序集“Microsoft.CodeAnalysis,版本=2.6.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 The system cannot find the file specified.. An instance of analyzer Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.CancellationTokenParametersMustComeLastAnalyzer cannot be created from \\packages\\Microsoft.CodeQuality.Analyzers.2.6.3\\analyzers\\dotnet\\cs\\Microsoft.CodeQuality.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.系统找不到指定的文件。无法从 \\packages\\Microsoft.CodeQuality.Analyzers.2.6.3\\analyzers\\dotnet\\cs\\Microsoft.CodeQuality.Analyzers 创建分析器 Microsoft.CodeQuality.Analyzers.ApiDesignGuidelines.CancellationTokenParametersMustComeLastAnalyzer 的实例.dll:无法加载文件或程序集“Microsoft.CodeAnalysis,版本=2.6.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。 The system cannot find the file specified..该系统找不到指定的文件..

Note: For the sake of conciseness, I've omitted 127 of the errors.注意:为了简洁起见,我省略了 127 个错误。 They are all very similar.它们都非常相似。 One thing to note, though, is that not all of the analyzers are in the Microsoft.CodeQuality namespace;但需要注意的一件事是,并非所有分析器都在 Microsoft.CodeQuality 命名空间中。 some are in Microsoft.NetCore, and some are in Microsoft.NetFramework.有些在 Microsoft.NetCore 中,有些在 Microsoft.NetFramework 中。

So I say ok, I must need to install Microsoft.CodeAnalysis v2.6.0.0 first.所以我说好的,我必须先安装Microsoft.CodeAnalysis v2.6.0.0。 Seems weird that that wouldn't be a dependency that's automatically installed by NuGet but whatever.看起来很奇怪,这不是 NuGet 自动安装的依赖项,但无论如何。

So I revert all my changes in Git, reopen the solution, install Microsoft.CodeAnalysis v2.6.0.0, and then install the latest stable version of Microsoft.CodeAnalysis.FXCopAnalyzers.所以我恢复了我在 Git 中的所有更改,重新打开解决方案,安装 Microsoft.CodeAnalysis v2.6.0.0,然后安装 Microsoft.CodeAnalysis.FXCopAnalyzers 的最新稳定版本。

Same errors!同样的错误!

When I look in packages/Microsoft.CodeAnalysis.2.6.0, I notice that there isn't a .dll anywhere in there.当我查看包/Microsoft.CodeAnalysis.2.6.0 时,我注意到那里没有 .dll 。 What is the correct way to install this?安装它的正确方法是什么? Is installing Microsoft.CodeAnalysis even the correct solution?安装 Microsoft.CodeAnalysis 甚至是正确的解决方案吗? Why aren't the dependencies of Microsoft.CodeAnalysis.FXCopAnalyzers automatically installed when you install it?为什么安装时没有自动安装Microsoft.CodeAnalysis.FXCopAnalyzers的依赖? Isn't that the whole point of a package manager?这不是包管理器的全部意义吗? I have so many questions and so few answers.我的问题太多,答案太少。 Please help.请帮忙。

This issue on the Roslyn analyzers github project suggested adding a reference to Microsoft.Net.Compilers v2.6.1. Roslyn 分析器 github 项目上的这个问题建议添加对Microsoft.Net.Compilers v2.6.1 的引用。 I can't find this package anywhere in the dependency chain for Microsoft.CodeAnalysis.FXCopAnalyzers, but I noticed that I had version 1.0.0 installed in my project.我在 Microsoft.CodeAnalysis.FXCopAnalyzers 的依赖链中的任何地方都找不到这个包,但我注意到我的项目中安装了 1.0.0 版。 I removed the package and installed v2.10.0, and now everything seems to be working as expected.我删除了软件包并安装了 v2.10.0,现在一切似乎都按预期工作。

For anyone running into this problem in the future just to point out that one of the reasons this may happen is because VS is outdated.对于将来遇到此问题的任何人,只是指出可能发生这种情况的原因之一是因为 VS 已过时。

A new installation or update of VS may solve the problem if the solution above doesn't.如果上述解决方案不能解决问题,则新安装或更新 VS可能会解决该问题。

1- Choose Release instead of Debug in Visual Studio 1- 在 Visual Studio 中选择Release而不是Debug

2-Build your solution 2-构建您的解决方案

Add on the *.csproj添加 *.csproj

<PropertyGroup>
  <OutputType>Exe</OutputType>
  <TargetFramework>netcoreapp3.1</TargetFramework>
  <EnableNETAnalyzers>true</EnableNETAnalyzers>
  <AnalysisMode>AllEnabledByDefault</AnalysisMode>
  <AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>

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

相关问题 SonarQube 没有找到 Microsoft.CodeAnalysis 1.3.1.0 但已安装 - SonarQube doesnt find Microsoft.CodeAnalysis 1.3.1.0 but it is installed 无法加载文件或程序集 Microsoft.CodeAnalysis - Could not load file or assembly Microsoft.CodeAnalysis 在Roslyn与Microsoft.CodeAnalysis中添加MetadataReference - Adding MetadataReference in Roslyn Vs Microsoft.CodeAnalysis Microsoft.CodeAnalysis无法加载文件 - Microsoft.CodeAnalysis failed to load file 在哪里阅读Microsoft.CodeAnalysis的文档? - Where to read docs for Microsoft.CodeAnalysis? 关于 Microsoft.CodeAnalysis.NetAnalyzers 和 FxCop 分析器的问题 - Question on Microsoft.CodeAnalysis.NetAnalyzers and FxCop analyzers Microsoft.CodeAnalysis:使用Newtonsoft JObject编译动态代码时出错 - Microsoft.CodeAnalysis: Error compiling dynamic code with Newtonsoft JObject 使用Roslyn(Microsoft.CodeAnalysis)查询WebSite项目的信息 - Using Roslyn (Microsoft.CodeAnalysis) to query information of WebSite projects 合并 SonarAnalyzer.CSharp 和 Microsoft.CodeAnalysis 规则集 - Merge SonarAnalyzer.CSharp and the Microsoft.CodeAnalysis rulesets 如何在 memory 中编译并使用 Microsoft.CodeAnalysis 获取程序集 - How to compile in memory and get assembly using Microsoft.CodeAnalysis
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM