在 Ubuntu 18.04 上构建脚本出现错误

Building scriptcs on Ubuntu 18.04 got errors

如何在 Ubuntu 18.04 上安装 scriptcs?我遇到了一些构建错误。

我正在尝试使用 Ubuntu 18.04 上的 Visual Studio 代码 运行 c# 代码。我下载了 VScode 并安装了扩展(C#、C# 扩展、C# XML 文档注释、Code Runner)。但是当我 运行 使用 ctrl+shift+p 时,它会抛出错误“/bin/sh: 1: scriptcs: not found”。因此,我为先决条件安装了 mono-complete,并尝试使用 https://github.com/scriptcs/scriptcs/wiki/Building-on-Mac-and-Linux 安装 scriptcs。但由于几个构建错误而失败。

下面是完整的错误代码

silvara@silvara-B85N-PHOENIX-WIFI:~/workspace/scriptcs$ sudo ./build.sh 
[sudo] password for silvara: 
Checking Paket version (prerelease requested)...
Paket.exe 5.203.2 is up to date.
Paket version 5.203.2
The last restore is still up to date. Nothing left to do.
Performance:
 - Runtime: 73 milliseconds
Building project with version: LocalBuild
Shortened DependencyGraph for Target Pack:
<== Pack
   <== Test
      <== Build
         <== Clean

The running order is:
  - Clean
  - Build
  - Test
  - Pack
Running build with 1 worker
Starting Target: Clean 
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs/bin
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/bin
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Core/bin
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Engine.Roslyn/bin
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Hosting/bin
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Core.Tests/bin
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Engine.Roslyn.Tests/bin
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Hosting.Tests/bin
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Tests/bin
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Tests.Acceptance/bin
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs/obj
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/obj
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Core/obj
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Engine.Roslyn/obj
Deleting /home/silvara/workspace/scriptcs/src/ScriptCs.Hosting/obj
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Core.Tests/obj
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Engine.Roslyn.Tests/obj
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Hosting.Tests/obj
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Tests/obj
Deleting /home/silvara/workspace/scriptcs/test/ScriptCs.Tests.Acceptance/obj
Finished Target: Clean
Starting Target: Build (==> Clean)
dotnet "restore" 
  Restore completed in 282.77 ms for /home/silvara/workspace/scriptcs/src/ScriptCs.Hosting/ScriptCs.Hosting.csproj.
  Restore completed in 283.22 ms for /home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/ScriptCs.Contracts.csproj.
  Restore completed in 283.22 ms for /home/silvara/workspace/scriptcs/src/ScriptCs.Core/ScriptCs.Core.csproj.
  Restore completed in 44.27 ms for /home/silvara/workspace/scriptcs/test/ScriptCs.Core.Tests/ScriptCs.Core.Tests.csproj.
  Restore completed in 45.37 ms for /home/silvara/workspace/scriptcs/test/ScriptCs.Hosting.Tests/ScriptCs.Hosting.Tests.csproj.
  Restore completed in 7.76 ms for /home/silvara/workspace/scriptcs/test/ScriptCs.Tests.Acceptance/ScriptCs.Tests.Acceptance.csproj.
  Restore completed in 364.93 ms for /home/silvara/workspace/scriptcs/src/ScriptCs/ScriptCs.csproj.
  Restore completed in 257.35 ms for /home/silvara/workspace/scriptcs/test/ScriptCs.Tests/ScriptCs.Tests.csproj.
  Restore completed in 392.31 ms for /home/silvara/workspace/scriptcs/test/ScriptCs.Engine.Roslyn.Tests/ScriptCs.Engine.Roslyn.Tests.csproj.
  Restore completed in 700.41 ms for /home/silvara/workspace/scriptcs/src/ScriptCs.Engine.Roslyn/ScriptCs.Engine.Roslyn.csproj.
Building project: ScriptCs.sln
  /usr/bin/msbuild  ScriptCs.sln /t:Build  /v:m  /p:RestorePackages="True" /p:Optimize="True" /p:Configuration="Release" /logger:Fake.MsBuildLogger+ErrorLogger,"/home/silvara/workspace/scriptcs/packages/FAKE/tools/FakeLib.dll"
Microsoft (R) Build Engine version 16.0.0.0 for Mono
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [/home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/ScriptCs.Contracts.csproj]
/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018: System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000027 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null) [/home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/ScriptCs.Contracts.csproj]
/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <c5e0e1dbe29a4fae9ad829d4b52ccc8b>:0  [/home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/ScriptCs.Contracts.csproj]
/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>:0  [/home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/ScriptCs.Contracts.csproj]
/usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x001f6] in <58f0218f988743a48dd7c84cbe933f4e>:0  [/home/silvara/workspace/scriptcs/src/ScriptCs.Contracts/ScriptCs.Contracts.csproj]
Running build failed.
Error:
Building ScriptCs.sln failed with exitcode 1.

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target     Duration
------     --------
Clean      00:00:00.0372588
Build      Failure
Total:     00:00:07.0042658
---------------------------------------------------------------------
Status:    Failure
---------------------------------------------------------------------
---------------------------------------------------------------------
  1) Building ScriptCs.sln failed with exitcode 1.
  2) MSB4018: /usr/share/dotnet/sdk/2.2.203/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(129,5): The "GenerateDepsFile" task failed unexpectedly.
  3) System.TypeLoadException: Could not load type of field 'Microsoft.NET.Build.Tasks.DependencyContextBuilder:_filteredPackages' (12) due to: Could not resolve type with token 01000027 from typeref (expected class 'NuGet.Packaging.Core.PackageIdentity' in assembly 'NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35') assembly:NuGet.Packaging, Version=5.0.0.6, Culture=neutral, PublicKeyToken=31bf3856ad364e35 type:NuGet.Packaging.Core.PackageIdentity member:(null)
  4)   at Microsoft.NET.Build.Tasks.TaskBase.Execute () [0x00000] in <c5e0e1dbe29a4fae9ad829d4b52ccc8b>:0 
  5)   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00029] in <58f0218f988743a48dd7c84cbe933f4e>:0 
  6)   at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x001f6] in <58f0218f988743a48dd7c84cbe933f4e>:0 
---------------------------------------------------------------------

这是一个临时的简单修复:

sudo apt install dotnet-sdk-2.2=2.2.105-1
sudo apt-mark hold dotnet-sdk-2.2
sudo ./build.sh

这是一个兼容性问题,Microsoft 没有动力去解决,因为我们使用的是 Linux...