我创建了一个玩具项目,用于检查最新的.NET 7(preview-5)和regex代码生成。它运行得很好,所以我将相同的更改应用于现有项目(不是为了生产,而是为了个人生产力)。出于某种原因,我收到了以下警告:
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..
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..
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
文件的相关部分:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>disable</ImplicitUsings>
<AnalysisLevel>latest-all</AnalysisLevel>
<EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Svg" Version="3.4.2" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<WarningLevel>1</WarningLevel>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<WarningLevel>1</WarningLevel>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
</PropertyGroup>
</Project>
我还尝试注解掉Svg依赖项和使用它的代码,但没有什么明显的变化。
为了便于比较和完成,下面是玩具项目的.csproj
文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<LangVersion>preview</LangVersion>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
我不明白为什么没有找到分析器。DLL肯定在那里。我怀疑它是Version=4.3.0.0
部分,但我不知道那个版本指的是什么,哪个版本是正确的,以及我应该在哪里指定它。
我找到的一个答案告诉我使用<TargetFrameworks>net7.0-windows;netstandard-2.0</TargetFrameworks>
(或非常类似的东西),但这不起作用。
我已经在网上搜索了几个小时了,似乎到目前为止还没有人遇到过这个问题;类似问题的解决方案对我不起作用。
编辑(2022年12月17日):将VS升级到某个版本后,问题消失。
1条答案
按热度按时间enxuqcxy1#
这是由.csproj文件中的
EnforceCodeStyleInBuild
属性(与.NET 7的预览版本结合使用)引起的Visual Studio问题。使用dotnet build
而不是VS生成项目不会产生警告(或移除EnforceCodeStyleInBuild
)。已提交issue以用于VS。