Xamarin.forms: XF002 - Xamarin.Forms tasks do not match targets

Created on 9 Jan 2018  ·  23Comments  ·  Source: xamarin/Xamarin.Forms

Description

Working in VS Enterprise 15.5.2 and Xamarin 2.5.0.121934
The error XF002 - Xamarin.Forms tasks do not match targets appeared after in the error list after the 3rd compile of a Xamarin project

Steps to Reproduce

  1. I opened existing Xamarin project
  2. debugged 3 times in a row via F5
  3. 4th time I hit F5, the error XF002 appeared in both the UWP and Common project (those are the only two that I am compiling) I believe that the most interesting info in this is that between the 3rd and 4th debugs I opened 2 more VS solutions and one of them was the Xamarin.Forms repro and that stresses the memory on my system.

Expected Behavior

No error message

Actual Behavior

Error XF002

Basic Information

  • Version with issue:
  • Last known good version:
  • IDE:
  • Platform Target Frameworks:

    • iOS: NA

    • Android: NA

    • UWP: 16299 -->

  • Android Support Library Version: NA
  • Nuget Packages:
  • Affected Devices:
5 high impact UWP bug

Most helpful comment

I resolved the issue by cleaning the soln first. And then closing the VS instant. Delete bin and obj folder, delete the temporary .vs folder and then reopen the soln.

All 23 comments

Also seeing this with 2.5.0.122203 in 15.5.3 and in the 15.6 preview.

Now seeing this again with v3 of Xamarin forms. Workaround (temp solution only) is to comment out the Error in the Xamarin.Forms.targets file.

@davidortinau is there a reason that this bug is still open? I assume it was fixed in 2.5 but the issue never closed off. Now it seems to be resurfacing in v3. Stability is still such an issue with XF!!

@nickrandolph I'll check with @jassmith. I believe it's still an issue we are supporting the build and IDE teams in resolving. I'll also check on their progress.

between the 3rd and 4th debugs I opened 2 more VS solutions and one of them was the Xamarin.Forms repro

@SOHODeveloper it's been a while since you reported this, but next time if you open or have had another solution open referencing Xamarin.Forms that throws this error, check that the versions were different between those solutions.

In too many cases things are staying in memory between solutions that triggers this error. The most reliable solution is to clean, close all instances of VS, and reopen the solution you want to work on.

@davidortinau I just did the following:

  • Launched VS
  • Opened MvvmCross (my branch that has v3 of XF referenced)
  • Cleaned solution
  • Closed and relaunched VS
  • Opened MvvmCross
  • Attempted to rebuild MvvmCross.Forms project
  • Build failed but not related to this issue

I guess this proves your point about it being related to upgrading/changing XF versions and VS holding onto references.

Updated Xamarin Forms this morning and now cannot compile solution.

The error message is:-

/Users///packages/Xamarin.Forms.3.0.0.482510/build/netstandard1.0/Xamarin.Forms.targets(3,3): Error XF002: Xamarin.Forms tasks do not match targets. Please ensure that all projects reference the same version of Xamarin.Forms, and if the error persists, please restart the IDE. (XF002)

The detail of this error is:-

/Users///packages/Xamarin.Forms.3.0.0.482510/build/netstandard1.0/Xamarin.Forms.targets(44,3)

Notice the error message and the detail both refer to Xamarin.Forms.targets but different numbers between the ().

Have tried cleaning the solution, quitting VS and restarting Mac but to no avail.

This helped me resolve this error

  1. Do a build of the PCL/Standard project, this will probably fail.
  2. Next after the build, do a Clean of the PCL/Standard project, this might fail too.
  3. After the above 2 steps, go ahead and Rebuild. Shoud work now.
  4. You can proceed to build any of the platform( Android or iOS) projects after the above steps.
    Just remember to always opt for a rebuild FIRST for the platform project first.

@ozzioma Why are we talking about PCLs? Any good reason not to use NET Standard library?

@opcodewriter I was referring to the Xamarin Forms "library" project which could be a PCL or a Net Standard project.
I had to go through the cycle I described to resolve the issue...or several permutations of it.
I figured the build task was stuck on resolving dependencies or cleaning out native packages during the build cycle...and one of the build/clean/rebuild actions helped trigger that successfully.

This just worked for me:

  1. Revert Xamarin.Forms to its prior version in the Forms project and your native project(s) (for me, I had to go from 3.1.0.583944 down one version to 3.0.0.561731 for Forms project and iOS)
  2. Clean/Build (this still failed)
  3. Update the packages in both projects back to current, and THEN Clean/Build which seemed to work 🤷‍♂️

Mileage may vary. I'm not sure if any of the other countless clean/build sequences leading up to these steps were also relevant, but I'd be interested to see if this work for anyone else (and for me the next time this inevitably happens..)

My discoveries so far.
There is a mismatch between the platform/CPU architecture target for the Standard project and the native projects (x86 or AnyCPU).
Make sure the targets are the same for both before running or building.
Most times when it bombs with the "tasks do not match targets" error, this is probably the cause.
Fixing this makes the error go away or so it seems.
Only snag is, while debugging the app in a simulator or physical device, if an exception gets thrown,
and you try to rerun the app after making some changes, Visual Studio throws up a "deployment errors" exception.
I typically fix this by changing the CPU target to say AnyCPU from x86 or vice versa.
Man this is tiring...

Using
Microsoft Visual Studio Enterprise 2017 Preview
Version 15.8.0 Preview 4.0
VisualStudio.15.Preview/15.8.0-pre.4.0+27906.1
Microsoft .NET Framework
Version 4.7.03056

Also using the new Hyper-V Android Emulator.

Possibly a cache or memory leak issue:

When creating a new Xamarin.Forms project or loading an existing XF project when have already loaded another get:

Severity Code Description Project File Line Suppression State
Error XF002 Xamarin.Forms tasks do not match targets. Please ensure that all projects reference the same version of Xamarin.Forms, and if the error persists, please restart the IDE. XamlTest2 C:\Users\DavidJones.nuget\packagesxamarin.forms\3.1.0.637273\build\netstandard2.0\Xamarin.Forms.targets 44

Solution is to close VS in both cases and restart VS and reload project.

I resolved the issue by cleaning the soln first. And then closing the VS instant. Delete bin and obj folder, delete the temporary .vs folder and then reopen the soln.

numb3r - thank you for that. Did the job. It is amazing what you have to know when you are usng Xamarin, it seems a very unstable product.

Here we go again. I just updated to Xamarin.Forms 3.1.0.697729 and this is happening all over again. Cleaning the solution fails (with the same error). Deleting bin and obj (no fix). Restarting VS (doesn't fix). I'm stuck in the water again rolling back to earlier versions. Took me hours last time.

Come on Xamarin people. This is basic. And it's unacceptable.

@ian-vitaexmachina can you please confirm there are absolutely not other versions of Xamarin.Forms referenced in your solution? Inspect each csproj or other config.

If all is well there, please provide us with details: version of VS, project types and config in your solution, solution files/proj files, or better yet the solution that exhibits this behavior.

@ian-vitaexmachina I have your version of forms installed and came here to fix this problem accordingly. I found numb3r's solution fixes it.

Had the same issue. Removing the Xamarin.Forms package and adding it again resolved the issue for me.

image

MSBuild.exe and VBCSCompiler.exe still there even though I just compiled
Delete them and build again work for me.

@PelleJuul thanks, it works. Removing and Adding only Xamarin.Forms from PCL. My version Xamarin.Forms is 3.1.0.697729. I think the version is the latest now.

I had the same error.
to resolve this problem, I migrated my Core libraries to .Net Standard 2.0 (1.6 before) and my UWP projets to the min version Fall Creators Update (Anniversary Update before)

However, the errors with Xamarin Forms are always complicated, and we loss a lot of time to debug.
It's boring, we need that Microsoft improves the tools!

The only thing that worked for me was to delete the error tag in the Xamarin.Forms.target file

This shouldn't happen on latest version of XF (because we do not throw the XF002 anymore). Some weird behavior can still happen if you have multiple versions of XF loaded at the same time (same solution, or in different IDE), but we try to mitigate that by strong-signing our task assemblies.

Was this page helpful?
0 / 5 - 0 ratings