首页 > 解决方案 > 2wpf .net5 错误当前上下文中不存在名称“InitializeComponent”

问题描述

我在 Visual Studio 2019 中创建了一个新项目并选择“WPF 应用程序”.net5 并尝试构建生成的应用程序,但出现了两个错误

当前上下文中不存在名称“InitializeComponent”。

程序不包含适用于入口点的静态“Main”方法。

我看到所有类似的问题并尝试所有解决方案
出了什么问题? 错误

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApp1"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>

    </Grid>
</Window>


using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace WpfApp1
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
    }
}

<Application x:Class="WpfApp1.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:WpfApp1"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
         
    </Application.Resources>
</Application>

标签: wpfvisual-studio-2019.net-5

解决方案


我创建了一个空解决方案并将其存档在 Google Disk Empty Application
上 下载并尝试在 Visual Studio 中打开它。
如果它打开,则意味着您的项目类型错误,或者用于创建解决方案的模板中存在错误。
如果它没有打开,那么 Studio 本身就有问题。

报告结果以了解在哪个方向寻找问题的解决方案。


推荐阅读