Bol*_*pat 5 .net c# visual-studio c#-11.0 .net-7.0
我创建了一个玩具项目来检查最新的 .NET 7(预览版 5)和正则表达式代码生成。它效果很好,所以我对现有项目应用了相同的更改(不是为了生产,而是为了个人生产力)。由于某种原因,我\xe2\x80\x99m 收到这些警告:
\nCS8032 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..\nCS8032 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..\nCS8033 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.\nRun Code Online (Sandbox Code Playgroud)\n文本Das System kann die angegebene Datei nicht finden..翻译为 \xe2\x80\x9c 系统找不到指定的文件,\xe2\x80\x9d 但这是 DeepL 翻译,实际的英文错误消息可能有所不同。
\n在前两个中,它\xe2\x80\x99s 超过 200 个具有相似精神的它们使用不同的分析器。
\n玩具项目是一个控制台应用程序,有问题的项目是一个 Windows 窗体应用程序(如果这在某种程度上相关的话)。这是 \xe2\x80\x93 我相信 \xe2\x80\x93 文件的相关部分.csproj:
<Project Sdk="Microsoft.NET.Sdk">\n <PropertyGroup>\n <OutputType>WinExe</OutputType>\n <TargetFramework>net7.0-windows</TargetFramework>\n <Nullable>enable</Nullable>\n <UseWindowsForms>true</UseWindowsForms>\n <ImplicitUsings>disable</ImplicitUsings>\n <AnalysisLevel>latest-all</AnalysisLevel>\n <EnforceCodeStyleInBuild>True</EnforceCodeStyleInBuild>\n <LangVersion>preview</LangVersion>\n </PropertyGroup>\n <ItemGroup>\n <PackageReference Include="Svg" Version="3.4.2" />\n </ItemGroup>\n <PropertyGroup Condition="\'$(Configuration)|$(Platform)\'==\'Debug|AnyCPU\'">\n <WarningLevel>1</WarningLevel>\n <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>\n </PropertyGroup>\n <PropertyGroup Condition="\'$(Configuration)|$(Platform)\'==\'Release|AnyCPU\'">\n <WarningLevel>1</WarningLevel>\n <CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>\n </PropertyGroup>\n</Project>\nRun Code Online (Sandbox Code Playgroud)\n我还尝试注释掉 Svg 依赖项和使用它的代码。这没有什么显着改变。
\n并且,为了比较和完成,这是.csproj玩具项目的文件:
<Project Sdk="Microsoft.NET.Sdk">\n <PropertyGroup>\n <OutputType>Exe</OutputType>\n <LangVersion>preview</LangVersion>\n <TargetFramework>net7.0</TargetFramework>\n <ImplicitUsings>enable</ImplicitUsings>\n <Nullable>enable</Nullable>\n </PropertyGroup>\n</Project>\nRun Code Online (Sandbox Code Playgroud)\n我不明白为什么没有找到分析器\xe2\x80\x99t。DLL 肯定在那里。我怀疑它\xe2\x80\x99s 是这个Version=4.3.0.0部分,但我不知道该版本指的是什么,哪个版本是正确的以及我\xe2\x80\x99d 在哪里指定的。
我发现的一个答案告诉我使用<TargetFrameworks>net7.0-windows;netstandard-2.0</TargetFrameworks>(或非常类似的东西),但这并没有\xe2\x80\x99 工作。
我\xe2\x80\x99已经在网上搜索了几个小时了,到目前为止似乎还没有人遇到这个问题;类似问题的解决方案对我来说不起作用。
\n编辑(2022-12-17):更新VS到某个版本后问题消失。
\n这是由 .csproj 文件中的属性引起的 Visual Studio 问题EnforceCodeStyleInBuild(与 .NET 7 预览版结合使用)。使用而不是 VS 构建项目dotnet build不会产生警告(或删除EnforceCodeStyleInBuild)。已提交VS问题。