Visual Studio没有检测到窗体

huangapple go评论49阅读模式
英文:

Visual Studio not detecting Forms

问题

我已检查了一个使用SDK-Style csproj文件创建的现有WinForms项目,但Visual Studio未将窗体识别为可设计的窗体。因此,WinForms设计器无法使用。

我还可以通过创建一个新的net6 WinForms项目,然后删除包含有关SubType信息的csproj.user文件来重现此问题。根据以前的Visual Studio版本中类似错误的信息,应自动检测并将窗体添加到csproj.user文件中。但对我来说似乎并没有发生。

Visual Studio版本:17.4.4

csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>
</Project>
英文:

I have checked out an existing WinForms using SDK-Style csproj file, and Visual Studio does not detect the forms as forms that can be designed. As such, the WinForms designer cannot be used.

I can also reproduce this issue by creating a new net6 WinForms project and then deleting the csproj.user file containing information about the SubType. After reading about similar bugs in previous Visual Studio versions, the forms should be automatically detected and added to csproj.user file. However, this does not appear to happen for me.

Visual Studio version: 17.4.4

csproj

&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  &lt;PropertyGroup&gt;
    &lt;OutputType&gt;WinExe&lt;/OutputType&gt;
    &lt;TargetFramework&gt;net6.0-windows&lt;/TargetFramework&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
    &lt;UseWindowsForms&gt;true&lt;/UseWindowsForms&gt;
    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
  &lt;/PropertyGroup&gt;
&lt;/Project&gt;

</details>


# 答案1
**得分**: 2

经过进一步测试和与Visual Studio支持团队的联系,我发现问题与“在单独的进程中运行代码分析”设置有关。如果禁用此设置,Visual Studio 无法自行检测表单。启用后,一切都按预期运行。

<details>
<summary>英文:</summary>

After further testing and contact with Visual Studio support, I figured out that the issue is related to the &quot;Run code analysis in separate process&quot; setting. If this setting is disabled, Visual Studio does not detect the forms on its own. After enabling it, everything works as expected.



</details>



# 答案2
**得分**: 0

你也可以手动运行一次代码分析。

这可以通过 Visual Studio 中的 "分析" 菜单完成。对我来说,这修复了一组窗体没有被识别为窗体,并且在设计器视图中未打开的情况(双击会进入代码视图)。

https://learn.microsoft.com/en-us/visualstudio/code-quality/how-to-run-code-analysis-manually-for-managed-code?view=vs-2022

<details>
<summary>英文:</summary>

You can also run code analysis once, manually. 

This can be done through the &quot;Analysis&quot; menu in VS. For me it fixed the situation where a set of forms was not recognized as such and did the forms did not open in designer view (double click gave me code view instead).

https://learn.microsoft.com/en-us/visualstudio/code-quality/how-to-run-code-analysis-manually-for-managed-code?view=vs-2022

</details>



huangapple
  • 本文由 发表于 2023年2月13日 23:57:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438287.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定