dotnet test on solution with Xamarin.Android

trampstertrampster Member ✭✭
edited December 2019 in General

I have updated my shared code to use dotnet standard 2.1 so I can use span. After doing this my nunit unit test project had to be converted to dotnet core so that it could reference the dotnet standard 2.1 project (full framework has no support past 2.0)

This means that I now need to run my test in my CI using dotnet test. I would like to do this at the solution level. However when I do so dotnet test gets upset about the Xamarin.Android project which it does not understand. The test still run fine but dotnet test returns an error code which fails the build.

Initially I got the following error:
error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.0.101\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk

I fixed this by adding a condition that the targets file exists, but that resulted in the following error which I don't know how to solve.

error MSB4057: The target "VSTest" does not exist in the project.

The Xamarin.Android project has no tests in it but there doesn't seem to be anyway to tell dotnet test to ignore it.

Anyone know how to work around this problem?

Tagged:

Best Answer

  • trampstertrampster ✭✭
    edited December 2019 Accepted Answer

    I solved it (in the most hacky way possible) by adding a VSTest target to the Xamarin.Android project that does nothing.

    Here are the modifications to the Xamarin.Android project to make it work:

    <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" Condition="Exists('$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets')" />
    <Target Name="VSTest" >
        <Message Text="No tests because this is a Xamarin.Android project" />
    </Target>
    

Answers

  • trampstertrampster Member ✭✭

    Things I have tried to no effect:
    --no-build
    --no-restore
    --filter

    dotnet test still tries to parse the Xamarin.Android project file regardless of these options and produces the error.

  • trampstertrampster Member ✭✭
    edited December 2019 Accepted Answer

    I solved it (in the most hacky way possible) by adding a VSTest target to the Xamarin.Android project that does nothing.

    Here are the modifications to the Xamarin.Android project to make it work:

    <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" Condition="Exists('$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets')" />
    <Target Name="VSTest" >
        <Message Text="No tests because this is a Xamarin.Android project" />
    </Target>
    
Sign In or Register to comment.