本文介绍了Xamarin.UITesting NU1201 错误:Android 8.1 与 .NETFramework 4.6.1 不兼容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近几天一直有一个小问题,我将在 Visual Studio 2017 上创建一个新的 Xamarin Forms 项目并添加一个 Xamarin.UITest 跨平台测试项目进行单元测试我收到一系列 NU1201 错误当我在 UITest 项目中引用 .Android 应用程序时.

Have been having a little issue for the last couple of days now where I will create a new Xamarin Forms project on Visual Studio 2017 and add a Xamarin.UITest Cross-Platform Test Project for unit testing I recieve a series of NU1201 Errors when I reference the .Android App in the UITest Project.

这是我得到的确切错误:

Here is the exact error i get:

Error NU1201    Project App1.Android is not compatible with net461 (.NETFramework,Version=v4.6.1) / win-x64. Project App1.Android supports: monoandroid81 (MonoAndroid,Version=v8.1)

我已经尝试过 Android 版本号,以查看 UITesting 包是否不支持最新的 android,但无论我针对的是什么版本的 android,问题仍然存在.

I have played around with the Android version numbers to see if the UITesting package doesnt support the latest android but no matter what version of android i target the problem remains the same.

这是项目的截图.所有代码都与默认项目相同,并在模拟器中正常运行,但仅当 Android 应用程序引用到 UITest 项目时才会产生这些错误.

Here is a screenshot of the project.All the code is unchanged from the default project and runs in the simulator fine but only produces these errors when the Android app is referenced to the UITest project.

推荐答案

经过数小时的测试和试用后解决了这个问题.我没有将 Android 项目添加到引用中,而是在 AppInitializer 中向 StartApp() 调用添加了另一个方法,如下所示:

Solved it after many more hours of testing and trialling. Instead of adding the Android project to the references, Within the AppInitializer I added another method to the StartApp() call like so:

public class AppInitializer
{
    public static IApp StartApp(Platform platform)
    {
        if (platform == Platform.Android)
        {
            return ConfigureApp.Android.InstalledApp("com.companyname.App1").StartApp();
        }

        return ConfigureApp.iOS.StartApp();
    }
}

因此,一旦我第一次通过模拟器运行了应用程序并安装在设备上,UITest 就会简单地使用模拟器上安装的 APK 而不是项目.

Therefore once I had already run the app via the emulator for the first time and installed on the device, the UITest simply uses the installed APK on the emulator instead of the project.

这篇关于Xamarin.UITesting NU1201 错误:Android 8.1 与 .NETFramework 4.6.1 不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 23:57