Search code examples
shellunit-testingxamarin.androidmonogithub-actions

MSB4019 Run Xamarin Android Unit Tests using Github Actions


Need to run Xamarin.Android specific Unit Tests using Github Actions. Everything builds OK, but when I trying to dotnet test got the following error:

error MSB4019: The imported project "C:\Program Files\dotnet\sdk\3.1.300\Xamarin\Android\Xamarin.Android.CSharp.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\3.1.300\Xamarin\Android\Xamarin.Android.CSharp.targets" is correct, and that the file exists on disk.

My script is:

 - name: UnitTests.Droid
      run: |
        dotnet restore
        nuget restore
        cd MobileAccess.UnitTests.Droid
        msbuild MobileAccess.UnitTests.Droid.csproj /verbosity:normal /t:Rebuild /p:Configuration=Release
        dotnet test

P.S. Solution-specific Unit Tests that do not affect Android run correctly


Solution

  • Was ably to run droid-specific unit tests in xamarin using:

        runs-on: windows-latest
        steps:
        - uses: actions/checkout@v1
        - uses: nuget/setup-nuget@v1
        - uses: microsoft/[email protected]  
        - name: UnitTests.Droid
          run: |
            nuget restore
            cd YourDroidUnitTestsCsprojDirectory
            msbuild YourDroidUnitTestsCsproj.csproj /verbosity:normal /t:Rebuild /p:Configuration=Release
    
        - name: Setup VSTest.exe
          uses: Malcolmnixon/Setup-VSTest@v3
    
        - name: VSTest
          run: |
            cd YourDroidUnitTestsDirectory
            cd bin
            cd Release
            cd netcoreapp3.0
            ls
            vstest.console MobileAccess.UnitTests.Droid.dll