Unity2018引用System.Windows.Forms.dll发布报错

Unity 2018发布到PC平台,要用到打开选择文件界面,需要引入System.Windows.Forms.dll

打开Visual Studio,选择菜单栏“项目>添加引用”,找到Unity的安装路径,选择\Editor\Data\Mono\lib\mono\2.0\System.Windows.Forms.dll

然后再把System.Windows.Forms.dll导入Unity里面

        System.Windows.Forms.OpenFileDialog od = new System.Windows.Forms.OpenFileDialog();
        od.Title = "请选择图片";
        od.Multiselect = false;
        od.Filter = "图片文件(*.jpg,*.png,*.bmp)|*.jpg;*.png;*.bmp";
        if (od.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            StartCoroutine(GetTexture("file://" + od.FileName));
        }

运行正常,可是发布到PC端编译报错。

The Assembly Mono.WebBrowser is referenced by System.Windows.Forms.But the dll is not allowed to be included or could not be found.

 

解决办法:

1:删除掉工程中的System.Windows.Forms.dll等文件
2:切换 .NET Standard 2.0 ->.NET 4.x
3:Asset 目录下添加 mcs.rsp文件,文件内容 " -r:System.Windows.Forms.dll "

 

官方解释:

https://docs.unity3d.com/Manual/dotnetProfileAssemblies.html

Referencing additional class library assemblies

If a Unity Project needs access to a part of the .NET class library API that is not compiled by default, the Project can inform the C# compiler in Unity. The behavior depends which .NET profile the Project uses.

意思就是引用.NET其他类库组件的时候需要配置来通知编译器编译。

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值