Visual Studio 为什么我收到未找到分析仪的警告?

j2qf4p5b  于 2022-12-30  发布在  其他
关注(0)|答案(1)|浏览(267)

我创建了一个玩具项目,用于检查最新的.NET 7(preview-5)和regex代码生成。它运行得很好,所以我将相同的更改应用于现有项目(不是为了生产,而是为了个人生产力)。出于某种原因,我收到了以下警告:

  1. CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.ValidateFormatString.CSharpValidateFormatStringDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll : Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=4.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. Das System kann die angegebene Datei nicht finden..
  2. CS8032 An instance of analyzer Microsoft.CodeAnalysis.CSharp.UseUTF8StringLiteral.UseUTF8StringLiteralDiagnosticAnalyzer cannot be created from C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CSharp.CodeStyle.dll : Exception has been thrown by the target of an invocation..
  3. CS8033 The assembly C:\Program Files\dotnet\sdk\7.0.100-preview.5.22307.18\Sdks\Microsoft.NET.Sdk\codestyle\cs\Microsoft.CodeAnalysis.CodeStyle.dll does not contain any analyzers.

文本 *Das System kann die angegebene Datei nicht finden.. * 翻译为“系统找不到指定的文件”,但这是DeepL翻译,实际的英语错误消息可能不同。
在前两个中,有200多个精神相似的人使用不同的分析仪。
玩具项目是一个控制台应用程序,有问题的项目是一个Windows窗体应用程序,如果这是某种相关的话。这是-我相信-.csproj文件的相关部分:

  1. <Project Sdk="Microsoft.NET.Sdk">
  2. <PropertyGroup>
  3. <OutputType>WinExe</OutputType>
  4. <TargetFramework>net7.0-windows</TargetFramework>
  5. <Nullable>enable</Nullable>
  6. <UseWindowsForms>true</UseWindowsForms>
  7. <ImplicitUsings>disable</ImplicitUsings>
  8. <AnalysisLevel>latest-all</AnalysisLevel>
  9. <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
  10. <LangVersion>preview</LangVersion>
  11. </PropertyGroup>
  12. <ItemGroup>
  13. <PackageReference Include="Svg" Version="3.4.2" />
  14. </ItemGroup>
  15. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
  16. <WarningLevel>1</WarningLevel>
  17. <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
  18. </PropertyGroup>
  19. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
  20. <WarningLevel>1</WarningLevel>
  21. <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
  22. </PropertyGroup>
  23. </Project>

我还尝试注解掉Svg依赖项和使用它的代码,但没有什么明显的变化。
为了便于比较和完成,下面是玩具项目的.csproj文件:

  1. <Project Sdk="Microsoft.NET.Sdk">
  2. <PropertyGroup>
  3. <OutputType>Exe</OutputType>
  4. <LangVersion>preview</LangVersion>
  5. <TargetFramework>net7.0</TargetFramework>
  6. <ImplicitUsings>enable</ImplicitUsings>
  7. <Nullable>enable</Nullable>
  8. </PropertyGroup>
  9. </Project>

我不明白为什么没有找到分析器。DLL肯定在那里。我怀疑它是Version=4.3.0.0部分,但我不知道那个版本指的是什么,哪个版本是正确的,以及我应该在哪里指定它。
我找到的一个答案告诉我使用<TargetFrameworks>net7.0-windows;netstandard-2.0</TargetFrameworks>(或非常类似的东西),但这不起作用。
我已经在网上搜索了几个小时了,似乎到目前为止还没有人遇到过这个问题;类似问题的解决方案对我不起作用。
编辑(2022年12月17日):将VS升级到某个版本后,问题消失。

enxuqcxy

enxuqcxy1#

这是由.csproj文件中的EnforceCodeStyleInBuild属性(与.NET 7的预览版本结合使用)引起的Visual Studio问题。使用dotnet build而不是VS生成项目不会产生警告(或移除EnforceCodeStyleInBuild)。已提交issue以用于VS。

相关问题