将 .NET 8 与 WinForms 结合使用时出现 CA1416 警告

问题描述 投票:0回答:1

我有一个较旧的 WinForms 应用程序,正在从 .NET 6 更新到 .NET 8。

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net8.0-windows</TargetFramework>
  <UseWindowsForms>true</UseWindowsForms>
  <Nullable>enable</Nullable>
  <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

但是现在我收到了数百个错误,例如以下内容。

3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\HtmlVisualizer.cs(92,21,92,40):警告CA1416:此调用站点在所有平台上均可访问。 “ListView.Items”仅在“windows”6.1 及更高版本上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(157,30,157,62):警告CA1416:此调用站点在所有平台上均可访问。仅支持“ListView.ColumnHeaderCollection.Add(string?)”:“windows”6.1 及更高版本。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(154,13,154,27):警告CA1416:此调用站点在所有平台上均可访问。 “ListView.Items”仅在“windows”6.1 及更高版本上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\HtmlVisualizer.cs(86,21,86,33):警告CA1416:此调用站点在所有平台上均可访问。 “TextBox.Text”仅在“windows”6.1 及更高版本上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(157,30,157,46):警告CA1416:此调用站点在所有平台上均可访问。 “ListView.Columns”仅在“windows”6.1 及更高版本上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416
3>C:\Users\jwood\Source\Repos\SoftCircuits\HtmlMonkey\TestHtmlParse\NodeVisualizer.cs(158,17,158,29):警告CA1416:此调用站点在所有平台上均可访问。 “ColumnHeader.Width”仅在“windows”6.1 及更高版本上受支持。 (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1416

我真的不明白这是怎么回事。我的解决方案包括非 WinForms 项目,但我不知道这会如何导致在所有平台上均可访问的错误。

我测试过,它与

net7.0-windows
配合得很好。我在 Windows 11 上运行。

有谁知道为什么我在 .NET 8 中遇到此错误?

c# .net winforms .net-core .net-8.0
1个回答
0
投票

我不知道为什么 Microsoft 没有为这一重大更改提供简单的解决方法。我尝试了建议的修复,但它只会导致其他问题。

我可以通过使用 .NET 8 创建一个新的 WinForms 项目,然后将文件复制到新项目来修复它。该修复对我有用。

© www.soinside.com 2019 - 2024. All rights reserved.