c# - 我的 WPF 应用程序的当前上下文中不存在名称“InitializeComponent”
问题描述
我最近将我的 .NET Framework 4.8 WPF 应用程序转换为 .NET5。当我编译应用程序时,出现以下错误
当前上下文中不存在名称“InitializeComponent”
我关注了这个链接,但对我没有多大帮助。
我检查了两者*.xaml
和*.cs
文件命名空间。
<Window x:Class="Cl.Wpf.MessageWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
SizeToContent = "WidthAndHeight"
Title="MessageWindow" >
还检查了.cs
文件
namespace Cl.Wpf
{
public partial class MessageWindow : Window
{
public MessageWindow()
{
InitializeComponent();
.....
}
我的*.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<OutputType>Library</OutputType>
<RootNamespace>Cl.Wpf</RootNamespace>
<Deterministic>false</Deterministic>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<UseWPF>true</UseWPF>
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.2.241603">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
</Project>
我还尝试删除obj
文件夹并重新启动 Visual Studio 2019,但也没有帮助我。
另外,尝试在XAML
文件中添加一些空间,但这也无济于事。
构建动作MessageWindow.xml
解决方案
似乎问题出在Microsoft Visual Studio Community 2019 Version 16.11.2
.
我重新安装了社区版本,但没有再次工作。
所以最后,我卸载了社区版本并重新安装Microsoft Visual Studio Professional 2019 Version 16.11.2
,幸运的是它对我有用。
我不确定这对其他用户有多大用处,但这对我有用。
推荐阅读
- javascript - 在输入变化时更新 Vue 减法方法
- c# - 如何以一定速度将精灵的速度设置为与鼠标指针相反的方向?
- javascript - 用 Enzyme/Jest 模拟 Click Test 不调用 Sinon Spy
- azure - 通过 azure 功能中的 powershell 更改网站集管理员
- nginx - NGinx 在同一个应用程序实例上拆分测试两个页面
- node.js - Firebase 身份验证 - REST API NodeJS
- android - 如何在 android 中使用 asp.net 信号器
- android - 从完整的日历日期格式中获取日期名称
- sorting - 在 MIPS 中按地址对值进行排序
- php - 基于两列的排名