WPF学习- 新建项目后自定义Main()[Type 'App' already defines a member called 'Main' with the same parameter types]

问题点:

在App.xaml.cs中自己添加Main方法,编译会出现如下报错:

错误 CS0111 类型“App”已定义了一个名为“Main”的具有相同参数类型的成员 

错误 Type 'App' already defines a member called 'Main' with the same parameter types 

错误 CS0017 程序定义了多个入口点。使用 /main (指定包含入口点的类型)进行编译。 

原因:

默认方式新建WPF项目时,编译时会自动生成Main方法(在App.g.i.cs中)。

解决方式:

在App.xaml的属性中,把生成操作 ApplicationDefinition 修改为Page。再编译就OK了。

【WPF项目在编译时,微软MSBuild:Compile 生成工具根据配置(ApplicationDefinition or Page) 做了不同的处理。】

MSBuild 相关参考:https://msdn.microsoft.com/zh-cn/library/dd393574.aspx

MSBuid 扩展:https://github.com/mikefourie/MSBuildExtensionPack

原文地址:https://www.cnblogs.com/kuangxiangnice/p/5576228.html