我决定尝试AppCenter CI在Android和iOS上构建我的Xamarin项目。
但是,我有一个构建错误,我不能直接在VisualStudio中构建时遇到。你知道如何解决这个问题吗?因为它告诉我运行Nuget包还原,但在构建期间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的构建设置中检查了Target 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.
最后解决了我的问题。
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>
现在我成功了。