Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error MSB4061: The "XamlCTask" task could not be instantiated

While trying to compile a Xamarin Forms (2.3.4.247) project on Visual Studio for Mac Community (7.0.1 [build 24]) I keep getting the two following errors after coding some time, any clue on what caused it and how to fix it?

/Users/PathToProjectRoot/packages/Xamarin.Forms.2.3.4.247/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.targets(3,3): Error MSB4061: The "XamlCTask" task could not be instantiated from "/Users/PathToProjectRoot/packages/Xamarin.Forms.2.3.4.247/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.Build.Tasks.dll". Could not load file or assembly 'Xamarin.Forms.Build.Tasks' or one of its dependencies (MSB4061) (ProjectName)
/Users/PathToProjectRoot/packages/Xamarin.Forms.2.3.4.247/build/portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20/Xamarin.Forms.targets(3,3): Error MSB4060: The "XamlCTask" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name. (MSB4060) (ProjectName)

What I have tried

  • Updated all packages and and SDKs.
  • Cleaned/Rebuild solution.
  • Removed all packages, closed VS, reopened and got all packages restored.
  • Removed all the bin and obj folders to try a rebuild.
  • Check the 3 .csproj for any outdated imports previous to 2.3.4.247.
  • Create a new solution.

What has worked

Creating a new clean solution using Xamarin Forms works however this causes all the packages to be from an old version. I've already done this twice but I'd like to be able to stop doing this as it takes a crazy amount of time to transfer all files from the broken project to the new one.

What hasn't worked

Besides all the things I've tried, it may be useful to mention that creating a new project after having cleared all the previous ones within the same solution doesn't fix the issue.
This makes me think that it is a solution-level error rather than a project-level error.

What packages are installed

Xamarin.Android.Support.Animated.Vector.Drawable.25.3.1
Xamarin.Android.Support.Annotations.25.3.1
Xamarin.Android.Support.Compat.25.3.1
Xamarin.Android.Support.Core.UI.25.3.1
Xamarin.Android.Support.Core.Utils.25.3.1
Xamarin.Android.Support.Design.25.3.1
Xamarin.Android.Support.Fragment.25.3.1
Xamarin.Android.Support.Media.Compat.25.3.1
Xamarin.Android.Support.Transition.25.3.1
Xamarin.Android.Support.Vector.Drawable.25.3.1
Xamarin.Android.Support.v4.25.3.1
Xamarin.Android.Support.v7.AppCompat.25.3.1
Xamarin.Android.Support.v7.CardView.25.3.1
Xamarin.Android.Support.v7.MediaRouter.25.3.1
Xamarin.Android.Support.v7.Palette.25.3.1
Xamarin.Android.Support.v7.RecyclerView.25.3.1
Xamarin.Build.Download.0.4.5
Xamarin.Forms.2.3.4.247

What Android platforms are installed

android-23
android-25

What file causes the errors

Error is caused by the file Xamarin.Forms.targets containing the following lines:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <UsingTask TaskName="Xamarin.Forms.Build.Tasks.XamlGTask" AssemblyFile="Xamarin.Forms.Build.Tasks.dll"/>
    <UsingTask TaskName="Xamarin.Forms.Build.Tasks.FixedCreateCSharpManifestResourceName" AssemblyFile="Xamarin.Forms.Build.Tasks.dll"/>
    <UsingTask TaskName="Xamarin.Forms.Build.Tasks.XamlCTask" AssemblyFile="Xamarin.Forms.Build.Tasks.dll"/>

    <!-- Some more lines here ...  -->

    <Target Name="XamlC">
        <!-- /!\ Error flagged at next line's "<" -->
        <XamlCTask
            Assembly = "$(IntermediateOutputPath)$(TargetFileName)"
            ReferencePath = "@(ReferencePath)"
            Verbosity = "2"
            OptimizeIL = "true"
            DebugSymbols = "$(DebugSymbols)"
            DebugType = "$(DebugType)"/>
    </Target>
</Project>

Latest updates

[June 16]

  • After trying to create a new solution several times, I'm now unable to create one that's able to build. Whatever version my packages are on, I keep getting those two errors.
  • See the Build output here.
like image 726
Faegy Avatar asked Jun 15 '17 19:06

Faegy


2 Answers

This issue was caused by the # character within the project's path. Removing it resolved the issue.

like image 112
Faegy Avatar answered Nov 15 '22 05:11

Faegy


Wired ... But closing visual studio and reopen solved the problem in my case

like image 39
Mohamed Saleh Avatar answered Nov 15 '22 05:11

Mohamed Saleh