'InitializeComponent'无法使用csc.exe编译WPF

时间:2016-03-12 02:13:44

标签: c# .net xaml

我知道这个问题已在StackOverflow上多次发布。我已经检查了这些帖子,但无法弄清楚我的程序中的错误 我下载了一个简单的WPF HelloWorld程序,并尝试使用命令行工具编译它:

csc.exe /out:WPFApplication.exe / target:winexe App.cs MainWindow.cs / reference:“C:\ Program Files \ Reference Assemblies \ Microsoft \ Framework \ v3.0 \ PresentationFramework.dll”/ reference: “C:\ Program Files \ Reference Assemblies \ Microsoft \ Framework \ v3.0 \ WindowsBase.dll”/ reference:“C:\ Program Files \ Reference Assemblies \ Microsoft \ Framework \ v3.0 \ PresentationCore.dll”

但我只收到错误消息“当前上下文中不存在名称'InitializeComponent'。”

这是App.cs:

using System.Windows;

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

的App.xaml:

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

MainWindow.cs:

using System.Windows;

namespace HelloWorld
{
  /// <summary>
  /// Interaction logic for MainWindow.xaml
  /// </summary>
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();
    }
  }
}

和MainWindow.xaml:

<Window x:Class="HelloWorld.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:HelloWorld"
  mc:Ignorable="d"
  Title="MainWindow" Height="350" Width="525" Icon="app.ico">
  <Grid>
    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">
      Hello, World!
    </TextBlock>
  </Grid>
</Window>

0 个答案:

没有答案