.netcore wpf程序引入COM控件
在.netcore wpf工程中引入COM控件时需要引入System.Windows.Forms支持,引用方法为在.csproj
文件中加入<UseWindowsForms>true</UseWindowsForms>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
问题
引入WinForm后在编译时,软件报命名空间冲突error CS0104: 'Application' is an ambiguous reference between 'System.Windows.Forms.Application' and 'System.Windows.Application'
。
解决方法
在.csproj
文件中添加如下配置项:
<!--防止与WPF中命名空间冲突-->
<ItemGroup>
<Using Remove="System.Windows.Forms" />
</ItemGroup>