英文:
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
<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>
</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 "Run code analysis in separate process" 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 "Analysis" 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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论