5

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.
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
Faegy
  • 942
  • 1
  • 12
  • 29
  • 1
    Simply close your solution and Xamarin Studio/VS. Go to your project folder and delete Bin & Obj folders from cross platform as well as from iOS, android project. Then open your project and rebuild it – Atul Jun 16 '17 at 02:39
  • I still got these two errors. – Faegy Jun 16 '17 at 08:03
  • 1
    Would it be possible that this error is created because a special character is in located in the file path (`.../C#/...`)? Everything seems functional outside this path. – Faegy Jun 16 '17 at 08:36
  • https://stackoverflow.com/questions/44302839/error-while-compiling-the-project –  Nov 29 '19 at 09:52

5 Answers5

5

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

Faegy
  • 942
  • 1
  • 12
  • 29
2

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

Mohamed Saleh
  • 2,881
  • 1
  • 23
  • 35
0

I had the same issue, it was caused by C:\User\name\.nuget folder being a symbolic link (created with MKLINK), which pointed to a directory on a bigger drive. When I set NUGET_PACKAGE environment variable to the actual location of the package directory, the issue is solved.

Matthias Lohr
  • 1,696
  • 2
  • 20
  • 32
0

I was facing a similar issue like yours. I updated many dependencies and removed a few.

I'm using this version of VS

enter image description here

I tried all the answers and didn't work.

I followed the "Just In Case" approach (mentioned in this answer thread previously.) of killing the VS instance and reopening it. Then when I executed the project all errors vanished.

Nagaraj Alagusundaram
  • 2,304
  • 2
  • 24
  • 31
0

In my case, I didnt have # in the path and I tried clean and rebuild,deleting obj,bin,packages folders, closed and opened many times etc but didnt work. My nuget packages folder is referenced at this path 'C:/Users/xyz/.nuget/packages/'

I tried to change the path of this nuget packages folder using a nuget.config file and placed it in the solution folder as specified in the below link and it worked.

Is it possible to change the location of packages for NuGet?

For me this piece of code worked among all the answers in the above link.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <config>
      <add key="globalPackagesFolder" value="C:\Projects\MyProj\.nuget\packages" />
      <add key="repositoryPath" value="C:\Projects\MyProj\.nuget\packages" />
    </config>
</configuration>