【发布时间】:2020-01-28 03:47:18
【问题描述】:
我是第一次尝试 WPF .NET Core,我在新的 WPF .NET Framework 项目中总是做的一件事是打开控制台,但是当我尝试这样做时收到错误消息在 .NET Core 中。
在面向 .NET Framework 的传统 WPF 中,这相当简单;
- 将 App.xaml 的构建操作设置为 Page
- 在某处定义一个 Main 方法,并用 STAThreadAttribute 标记它
- 在项目设置中,将输出类型设置为 Console Application,并将 Startup 对象设置为您放置 Main 方法的位置
我在 WPF .NET Core 中复制了这些步骤,但是当我尝试更改 App.xaml 的构建操作时出现错误
错误(在属性窗口的下拉菜单中选择页面后立即发生):
An error has occurred while saving the edited properties listed below:
Build Action
One or more values are invalid.
Cannot add 'App.xaml' to the project, because the path is explicitly excluded from the project
(C:\Program Files\dotnet\sdk\3.0.100\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.NET.Sdk.WindowsDesktop.targets (45,5)).
有没有人知道解决这个问题的方法,或者在 WPF .NET Core 中启用控制台的另一种方法?
【问题讨论】: