如何修复AppCenter构建错误NETSDK1004

时间:2019-03-17 14:33:03

标签: xamarin.forms xamarin.android visual-studio-app-center

我决定尝试使用AppCenter CI在Android和iOS上构建我的Xamarin项目。

但是,直接在Visual Studio中进行构建时,我遇到了一个构建错误。你知道如何解决这个问题吗?原因是它告诉我要运行Nuget Package还原,但是在构建过程中已还原了NugetPackage。

Installed:
    168 package(s) to packages.config projects
##[section]Finishing: Restore Nuget
##[section]Starting: Build Xamarin.Android project 

error NETSDK1004: Assets file '/Users/vsts/agent/2.148.1/work/1/s/MyProject/MyProject/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/vsts/agent/2.148.1/work/1/s/MyProject/MyProject/MyProject.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.99
##[error]Error: /Library/Frameworks/Mono.framework/Versions/5_16_0_0/bin/msbuild failed with return code: 1

构建输出日志:

https://drive.google.com/open?id=1uWbhzDOEF6KoRlC8iGhD_ro9NEyeODu5

我在AppCenter的构建设置中检查了目标SDK版本,我的目标是SDK 9.1(Mono 5.16)...但是,我将其更改为SDK 9.0(Mono 5.12),因此我要定位的目标我的项目,可能仍然在这里。

编辑:Appcenter恢复nuget包时,我也注意到此错误:

[command]/bin/bash -c /usr/bin/find . -name '*.sln' -type f -print0 | /usr/bin/xargs -0 grep -l '***.Droid.csproj' | /usr/bin/xargs -I '{}' nuget restore '{}' -DisableParallelProcessing
MSBuild auto-detection: using msbuild version '15.0' from '/Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/msbuild/15.0/bin'.
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018: The "WriteRestoreGraphTask" task failed unexpectedly. [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018: NuGet.Commands.RestoreCommandException: PackageTargetFallback and AssetTargetFallback cannot be used together. Remove PackageTargetFallback(deprecated) references from the project environment. [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at NuGet.Commands.AssetTargetFallbackUtility.EnsureValidFallback (System.Collections.Generic.IEnumerable`1[T] packageTargetFallback, System.Collections.Generic.IEnumerable`1[T] assetTargetFallback, System.String filePath) [0x0002d] in <55431ab4846b49babe0aafcf24cd67ed>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at NuGet.Commands.MSBuildRestoreUtility.AddPackageTargetFallbacks (NuGet.ProjectModel.PackageSpec spec, System.Collections.Generic.IEnumerable`1[T] items) [0x000cb] in <55431ab4846b49babe0aafcf24cd67ed>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at NuGet.Commands.MSBuildRestoreUtility.GetPackageSpec (System.Collections.Generic.IEnumerable`1[T] items) [0x002b3] in <55431ab4846b49babe0aafcf24cd67ed>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at System.Linq.Enumerable+SelectEnumerableIterator`2[TSource,TResult].MoveNext () [0x00048] in <cc3b329d40bd4675ae0e985e302972af>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext () [0x0004e] in <cc3b329d40bd4675ae0e985e302972af>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at NuGet.Commands.MSBuildRestoreUtility.GetDependencySpec (System.Collections.Generic.IEnumerable`1[T] items) [0x001f8] in <55431ab4846b49babe0aafcf24cd67ed>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at NuGet.Build.Tasks.WriteRestoreGraphTask.Execute () [0x000a5] in <55431ab4846b49babe0aafcf24cd67ed>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in <2338fdb301034c1d9c6b95e564d514b0>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]
/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/wnqwdckn.p7q.nugetrestore.targets(143,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder+<ExecuteInstantiatedTask>d__26.MoveNext () [0x00212] in <2338fdb301034c1d9c6b95e564d514b0>:0  [/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/NuGetScratch/u4qrmymw.ehn.nugetinputs.targets]

WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.

2 个答案:

答案 0 :(得分:0)

最终修复了我的问题。

1 /我的项目中有一个不在nuget上的外部程序集。我读到,如果有不依赖于Nuget的程序集,则appcenter无法构建项目/还原nuget。因此,我使用作者提供的nuget更新了该程序集。

2 /用原木进行的编辑使我走上了正确的道路。

  

“ WriteRestoreGraphTask”任务意外失败

解决方案是编辑项目.csproj并修改允许在.NET 4.5上回退的行

<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>

<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

Ref:https://intercom.help/appcenter/build/xamarin/xamarin-build-fails-with-the-writerestoregraphtask-task-failed-unexpectedly

现在,我的构建成功了。

答案 1 :(得分:0)

NETSDK1004出现类似错误。似乎project.assets.json从未因为早期失败而生成。

产生错误

error NETSDK1004: Assets file '/Users/runner/work/1/s/.../project.assets.json' not found. Run a NuGet package restore to generate this file.

实际错误

对于我来说,App Center的9_Restore_Nuget任务中有一个更早的错误:NETSDK1045。

error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.1. 

我已经在其中放置了一个以net core 3.1为目标的DLL-App Center不喜欢它,然后软件包恢复失败。

因此,原始错误是正确的-project.assets.json不存在,但是有一个原因&需要在构建过程中更早地进行探索。