错误 MSB4061:无法实例化 "XamlCTask" 任务

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

尝试在 Visual Studio 上为 Mac 社区(7.0.1 [build 24])编译 Xamarin Forms (2.3.4.247) 项目时,我在编写一些代码后不断收到以下两个错误时间,关于导致它的原因以及如何解决它的任何线索?

/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)

我试过的

什么有效

使用 Xamarin Forms 创建新的干净解决方案是可行的,但这会导致所有包都来自旧版本。我已经这样做了两次,但我希望能够停止这样做,因为将所有文件从损坏的项目传输到新项目需要大量时间。

什么没用

除了我尝试过的所有事情之外,提一下在清除 same 解决方案中的所有先前项目后创建一个新项目可能不会修复问题。
这让我认为这是一个解决方案级别的错误,而不是项目级别的错误。

安装了哪些包

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

安装了哪些 Android 平台

android-23
android-25

什么文件导致错误

错误是由包含以下行的文件 Xamarin.Forms.targets 引起的:

<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>

最新更新

[6 月 16 日]

此问题是由项目路径中的 # 字符引起的。删除它解决了这个问题。

有线...但关闭 visual studio 并重新打开解决了我的问题

我有同样的问题,这是由于 C:\User\name\.nuget 文件夹是一个符号 link(使用 MKLINK 创建),它指向更大驱动器上的目录。当我将 NUGET_PACKAGE 环境变量设置为包目录的实际位置时,问题就解决了。

我遇到了和你类似的问题。我更新了许多依赖项并删除了一些。

我正在使用这个版本的 VS

我尝试了所有的答案,但没有成功。

我遵循“以防万一”的方法(在之前的回答线程中提到过。)终止 VS 实例并重新打开它。然后,当我执行该项目时,所有错误都消失了。

就我而言,我的路径中没有#,我尝试了清理和重建、删除 obj、bin、packages 文件夹,多次关闭和打开等,但没有成功。 在此路径 'C:/Users/xyz/.nuget/packages/'

中引用了我的 nuget 包文件夹

我尝试使用 nuget.config 文件更改此 nuget 包文件夹的路径,并将其放置在下面 link 中指定的解决方案文件夹中并且成功了。

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

对我来说,这段代码在上面的所有答案中都起作用 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>