xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Mixed Xamarin.Forms versions causes error MSB4064: The "ValidateOnly" parameter is not supported by the "XamlCTask" task #8209

Open Eilon opened 5 years ago

Eilon commented 5 years ago

Description

If you have a project that transitively references different versions of Xamarin.Forms, you get errors like this:

2>------ Rebuild All started: Project: XFTransitiveMismatch, Configuration: Debug Any CPU ------
2>C:\Users\elipton\.nuget\packages\xamarin.forms\4.3.0.908675\build\Xamarin.Forms.targets(116,4): error MSB4064: The "ValidateOnly" parameter is not supported by the "XamlCTask" task. Verify the parameter exists on the task, and it is a settable public instance property.
2>C:\Users\elipton\.nuget\packages\xamarin.forms\4.3.0.908675\build\Xamarin.Forms.targets(110,3): error MSB4063: The "XamlCTask" task could not be initialized with its input parameters.
2>Done building project "XFTransitiveMismatch.csproj" -- FAILED.

There seems to be little information on the Internet about this.

If you consolidate all Xamarin.Forms packages to a single version, that fixes it.

However, in some cases you might be using 3rd party packages that have different dependencies and you can't consolidate on your own, leaving a developer to be stuck.

Steps to Reproduce

  1. Create a Xamarin.Forms project using, let's say, Xamarin.Forms 4.3
  2. Create a Class Lib project that references, say, Xamarin.Forms 4.2
  3. Add a reference from the shared Xamarin.Forms project to the new Class Lib project
  4. Try to build

Expected Behavior

In preference order:

  1. (Best) It should build
  2. (OK) Have a clear error message stating that there is likely a version incompatibility

Actual Behavior

You get an error with a difficult-to-diagnose error.

Reproduction Link

  1. Clone this repo: https://github.com/Eilon/XFTransitiveMismatch
  2. Try to build from either command line (MSBuild) or in VS (only tried VS for Windows 16.4 Preview 2)

Details of the solution:

  1. SharedXFProject --> Xamarin.Forms 4.3
  2. SharedXFProject --> XamarinFormsSuperExtensions --> Xamarin.Forms 4.2

Possibly related issues

The following issues look like they could be mitigated by a fix for the root cause of this issue:

Thoughts on possible fixes

Perhaps have some detection logic in the Targets or in the Task DLL that states its version, and check that version against its other half to ensure that a new task isn't run by an old target, or perhaps worse, an old task is run by a new target (this bug).

yanxiaodi commented 4 years ago

I have the same issue when upgrading Xamarin.Forms from v4.2 to v4.3. But I'm not using mixed Xamarin versions. I just have a Uwp project that references some .net standard 2.0 projects.

Eilon commented 4 years ago

@yanxiaodi do you have details on your solution/project structure? Or a repro project you can share on GitHub?

yanxiaodi commented 4 years ago

@Eilon Sorry my fault. I checked my solution and some other .net standard projects also reference Xamarin.Forms. The error is gone after I upgrade all the Xamarin.Forms versions.

yanxiaodi commented 4 years ago

@Eilon Sorry my fault. I checked my solution and some other .net standard projects also reference Xamarin.Forms. The error is gone after I upgrade all the Xamarin.Forms versions.

rezamohamed commented 4 years ago

I am also starting to see this message intermittently. This happens randomly, I would be able to build and deploy successfully multiple times, and then randomly the build would fail. The only solution is to close VS19 and open the project again.

image

Using Xamarin.Forms 4.3.0.991211, no updates, same nuget packages across my iOS and Android solutions.

Nullstr1ng commented 4 years ago

image Same here .. It's completely wasting my time. I have been rebuilding/cleaning - rebuilding/cleaning back and forth on the projects in my solution. The build succeeded after cleaning, the fails agian.

Wasted a lot of my time that is supposed to be for fixes and updates in our project.

What's funny is that, the build fails even after cleaning or restarting VS, but after restarting the OS, the build succeeded... Doesn't make any sense to me in my level.

-- XF 4.3.0.991211

Nullstr1ng commented 4 years ago

oh yeah,, we also have ah command that automajically removes all OBJ and BIN folders inside the solution.. still no luck.

bill2004158 commented 4 years ago

same error. tmp solution: open that target file, remove param ValidateOnly.

gezanna commented 4 years ago

Oh...spent a day trying to build my project, but still that the error keep blocking me.

Eilon commented 4 years ago

@gezanna - are you able to move all your projects to use the same version of Xamarin.Forms?

JunielKatarn commented 4 years ago

I have a project with only one reference to Xamarin.Forms. All 4.3.x series fail to build on UWP with this error. The workaround was to revert to latest 4.2.x. Note, the issue still shows up in latest preview 4.4.0.991210-pre2.

gezanna commented 4 years ago

@Eilon, sorry for my late reply. However all my projects use the same version 4.3.x. I guess i will have to revert back to 4.2.x, and restart from there. It's so painful though.

marthinch commented 4 years ago

I've solved this problem by re-install xamarin form on my project.

anasalweish commented 4 years ago

I Followed these steps to solve this problem after I upgrade XF from 4.2 to 4.4 using VS 2019

1- Clean All Solutions 2- Rebuild All 3- Close & Re-Open VS

yousufctec commented 4 years ago

I Followed these steps to solve this problem after I upgrade XF from 4.2 to 4.4 using VS 2019

1- Clean All Solutions 2- Rebuild All 3- Close & Re-Open VS

Order is wrong. Step 1, Step 3, Step 2 worked for me.

keozx commented 4 years ago

This still happens randomly in 4.4 stable, not related to different versions, can someone leave this open?

mathmul commented 4 years ago

I got here because of the same error. Read everything you guys wrote and it gave me an idea of what could be the cause of error in my case.

The solution I was working on had the same Xamarin.Forms version (v4.4) on all three projects (App, App.Android, App.iOS). It wouldn't deploy due to 4 errors, two of them verbosely related to XamlCTask.

Now the problem was that I was copying bits of code from another solution opened in a different window of the same Visual Studio 2019 Community. That one indeed had a different Xamarin.Forms version. The two solution aren't related in any way, since I just got cloned the other one minutes before the error. Closing both windows and reopening just my solution did the trick.

Hope it helps anyone.

PS: I understand that this has nothing to do with how the error is treated by VS and if it explains anything useful the the user wanting to debug the error.

mishrapw commented 4 years ago

@Eilon Can somebody suggest me way out of this issue ? Below step does not help at all: 1- Clean All Solutions 2- Rebuild All 3- Close & Re-Open VS

keozx commented 4 years ago

I could reproduce the error again by going to a 4.3 branch (same project), rebuild and go to a 4.4 and rebuild. Unloaded the project reporting the Xamlctask error (I have several projects with several Views in it, same XF version) and removed it's dependencies from Core project. Rebuild works. Reloading the "offending" project and rebuild breaks it again with same XamlcTask error

Still figuring out what would it be Xamarin build does not like about my project.

Target XamlC:
13>  Building target "XamlC" completely.
13>  Output file "obj\Debug\netstandard2.0\XamlC.stamp" does not exist.
13>  Using "XamlCTask" task from assembly "C:\Users\J\.nuget\packages\xamarin.forms\4.4.0.991265\build\net46\Xamarin.Forms.Build.Tasks.dll".
13>  Task "XamlCTask"
13>    C:\Users\J\.nuget\packages\xamarin.forms\4.4.0.991265\build\Xamarin.Forms.targets(116,4): error MSB4064: The "ValidateOnly" parameter is not supported by the "XamlCTask" task. Verify the parameter exists on the task, and it is a settable public instance property.
13>    C:\Users\J\.nuget\packages\xamarin.forms\4.4.0.991265\build\Xamarin.Forms.targets(110,3): error MSB4063: The "XamlCTask" task could not be initialized with its input parameters.
13>  Done executing task "XamlCTask" -- FAILED.
Eilon commented 4 years ago

Between builds did you do a git clean -xdf to remove all generated files? Sometimes changing package/reference versions leaves old stuff in the bin/obj folders. That git command will delete all files not in source control (so be careful 😄 ).

keozx commented 4 years ago

@Eilon you rock! I did't know about that super clean command, much better than VS clean, that fixed one part of the problem of reproducing the solution. For me the the "root" cause seems to be related to the csproj file artifacts created when adding new views or copying ones like these things:

<None Update="App.xaml">
      <Generator>MSBuild:Compile</Generator>
    </None>
<ItemGroup>
    <EmbeddedResource Update="Folder\SomeView.xaml">
      <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
    </EmbeddedResource>
<Compile Update="Folder\SomeView.xaml.cs">
      <DependentUpon>SomeView.xaml</DependentUpon>
    </Compile>

The "fix" is just to delete all these, I think the new csproj structure does not need it, this may create some files xamarin won't like, which are gone with the git clean.

From this can't really tell the root cause but hope there is an answer for that.

Eilon commented 4 years ago

VS/MSBuild Clean only cleans up things that the current state of the build knows about. So once you change dependencies, VS no longer knows that you once had some other settings in a previous state, so it won't/can't clean up certain stale contents. git clean -xdf doesn't care about any of that 😄

Enohara commented 4 years ago

I've solved this problem by re-install xamarin form on my project.

This helps a lot, thanks 😊

mkieres commented 4 years ago

I'm having the same problems in my DevOps pipeline.

Below some YAML from my pipeline to potentially help identify or narrow down the possible issues:

Host agent: macos-latest Xamarin SDK: - script: sudo $AGENT_HOMEDIRECTORY/scripts/select-xamarin-sdk.sh 6_6_0 (NOTE: I tried also with 6_4_0 version, which gave the same results) Using XamariniOS@2 task to build

Can provide logs if that might help.

jitendrajadav commented 4 years ago

I have same problem but it giving me error on AppCenter app is running fine

keozx commented 4 years ago

I have fixed it "permanently" by removing any implicit reference to different versions, you may have implicit references on projects not referencing XF directly which will take the min XF version of other dependency, things like Lottie, Prism.Forms, etc. You can see that in build output also.

Just explicitly install XF on all csproj directly or indirectly using XF.

Still a mistery why git clean -xdf work (sometimes)

labChariot commented 4 years ago

Upgrading from XF 4.3 to 4.4 was all I needed to do

lindexi commented 4 years ago

I update to xf 4.5

mkieres commented 4 years ago

I'm not sure what you mean @lindexi by saying that you've updated to latest stable Xamarin.Forms but I've done the same (update my project to latest Xamarin.Forms 4.5.0.356) and the build in my DevOps pipeline is still throwing same errors.

lindexi commented 4 years ago

@mkieres I upgrade to 4.5 from 4.3 and solve it. And before I upgrade it, I try to clean my code by git clean -xdf but can not solve it.

SatinderSidhu commented 4 years ago

I have removed all packages & reinstalled the one I need. Even then this issue is killing me /Users/satindersidhu/Projects/PunjabiMaa/packages/Xamarin.Forms.4.5.0.396/build/Xamarin.Forms.targets(90,4): error MSB4064: The "XamlFiles" parameter is not supported by the "XamlGTask" task. Verify the parameter exists on the task, and it is a settable public instance property. /Users/satindersidhu/Projects/PunjabiMaa/packages/Xamarin.Forms.4.5.0.396/build/Xamarin.Forms.targets(89,3): error MSB4063: The "XamlGTask" task could not be initialized with its input parameters. 0 Warning(s) 2 Error(s)

image

pmahend1 commented 4 years ago

Its happening for me on VS mac latest version 8.5.2 build 13

vividos commented 4 years ago

For your information, this error also occurs for me at work. We're using Xamarin.Forms 4.5.0.617, all packages are on the same version number. Only the incremental builds fail sporadically (done with /t:Build); full rebuilds work without problems. Maybe this info is helpful for finding the error.

vividos commented 4 years ago

After some more testing I get the impression that this error also appears when building two separate solutions, one with an older Xamarin.Forms NuGet package and one with 4.5.0.617. My guess is that there are MSBuild processes still active from a 4.2.0 build that has the Xamarin.Forms.Build.Tasks.dll loaded, and then a build with Forms 4.5.0 reuses this MSBuild process but can't find the ValidateOnly property, since the 4.2.0 .dll is still loaded. Worth checking your processes with Process Explorer which one of the .dlls is loaded. I don't know yet how to force the MSBuild tasks to either unload the .dll or to exit.

vividos commented 4 years ago

Here's a link with a workaround (not reusing MSBuild processes in automated builds) that may help some of you with this problem: https://nftb.saturdaymp.com/fixing-msbuild-not-exiting/

mnxamdev commented 4 years ago

This is happening for my team on AppCenter Build but not locally. We are running Xamarin.Forms 4.6 on UWP but previously was 4.4 and still causing issues. We upgraded hoping it'd fix this.

mnxamdev commented 4 years ago

This is happening for my team on AppCenter Build but not locally. We are running Xamarin.Forms 4.6 on UWP but previously was 4.4 and still causing issues. We upgraded hoping it'd fix this.

We fixed this by making all projects use the same version of Xamarin.Forms. The problem was our UnitTest project.

hartez commented 4 years ago

I've run into this when updating Xamarin.Forms versions from older (circa 2.4) versions to 4.x. If you've tried everything else and you're still seeing this error, check your build output to see if an old cached version of the XamlCTask (from a previous Forms version) is being loaded.

In that case, you may be able to fix it by clearing your NuGet cache:

  1. Close Visual Studio
  2. Clear out your NuGet cache with nuget locals all -clear.
  3. Reopen Visual Studio and build again.
alex4998 commented 4 years ago

I confirm, the root cause of the issue is different versions of Xamarin.Forms in the solution. In my case it was very surprising. Different versions were used in completely unrelated projects. There was no reference between them whatsoever. All of the projects referenced Xamarin.Forms of version 4.6.x but I had a Tizen project in the solution and that Tizen project referenced another project and that other project referenced Xamarin.Forms of version 4.2.x. Even though 4.2.x version was referenced in the Tizen project the error was displayed for one of the other projects. Every time it could be a different project and the issue was sporadic. Fortunately I could update the project version for Tizen project to 4.6.x and that resolved the issue once and for all.

david-js commented 4 years ago

I ran into this a little differently than anyone else so far (I think):

The root cause was the ZXing.Net.Mobile.Forms 2.4.1 nuget which we were using. This made the VS Mac build pull in Xamarin.Forms 2.5, resulting in the conflicting versions of Forms. Luckily we could drop the nuget, so that was our solution, and the VS Mac build works for us now.

This looks a lot like a bug in Visual Studio Mac. Since the build succeeded on Windows, it should have succeeded on VS Mac. The netstandard project in our solution is not platform dependent, so shouldn't have different build results.

nznaza commented 4 years ago

@david-js

This looks a lot like a bug in Visual Studio Mac. Since the build succeeded on Windows, it should have succeeded on VS Mac. The netstandard project in our solution is not platform dependent, so shouldn't have different build results.

I did had this problem too on a Mac but @hartez solution allowed the project to compile and run

1. Close Visual Studio

2. Clear out your NuGet cache with `nuget locals all -clear`.

3. Reopen Visual Studio and build again.

I do also have different dependencies versions on a solution and encountered this problem after adding a project (.csproj) targeting a previous version

Coruscate5 commented 3 years ago

BTW - I had this issue, and had failed to realize that Xamarin.Forms had been installed at the solution level as well as in the separate projects.

I had to update the solution level Xamarin.Forms package in order for the sub-projects (with the same XF version) to start working.