【问题标题】:dotnet rosalyn compiler error MSB6006: "csc.exe" exited with code 8dotnet rosalyn 编译器错误 MSB6006:“csc.exe”以代码 8 退出
【发布时间】:2018-11-27 12:49:40
【问题描述】:

我在尝试运行 dotnet build 命令时在 amazon linux 中遇到此错误。 我正在尝试使用 sonarqube .net 核心扫描仪,并将其作为运行 dotnet build 命令的一部分。

sudo dotnet build --no-restore --verbosity d --no-dependencies
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 11/27/18 11:42:22 AM.
1>Project "/var/lib/jenkins/workspace/multibranch_pipeline_master-VFQZN2R7JTITZDJOVBS6UDCECP2XJL7TD55373F64OTKZXE63T4Q/source/WebServer/UP/DotNetAPI/DotNetAPI.csproj" on node 1 (Build target(s)).
1>Building with tools version "15.0".
Project file contains ToolsVersion="". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="15.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=293424.
1>Target "Build" in project "/var/lib/jenkins/workspace/multibranch_pipeline_master-VFQZN2R7JTITZDJOVBS6UDCECP2XJL7TD55373F64OTKZXE63T4Q/source/WebServer/UP/DotNetAPI/DotNetAPI.csproj" (entry point):
Using "Csc" task from assembly "/opt/dotnet/sdk/2.0.0/Roslyn/Microsoft.Build.Tasks.CodeAnalysis.dll".
Task "Csc"
/opt/dotnet/sdk/2.0.0/Roslyn/csc.exe /out:/DotNetAPI.dll /target:library ReliabilityMain.cs
1>/var/lib/jenkins/workspace/multibranch_pipeline_master-VFQZN2R7JTITZDJOVBS6UDCECP2XJL7TD55373F64OTKZXE63T4Q/source/WebServer/UP/DotNetAPI/DotNetAPI.csproj(10,5): error MSB6006: "csc.exe" exited with code 8.
Done executing task "Csc" -- FAILED.
1>Done building target "Build" in project "DotNetAPI.csproj" -- FAILED.

我的.csproj文件如下图

```
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
   <TargetFramework>netcoreapp2.0</TargetFramework>
 </PropertyGroup>
  <ItemGroup>  
    <Compile Include="ReliabilityMain.cs"/>
    <PackageReference Include="Microsoft.Net.Compilers" Version="2.4.0" />
  </ItemGroup>  
  <Target Name="Build">  
    <Csc Sources="@(Compile)"
    TargetType="library"
     OutputAssembly="$(builtdir)\$(MSBuildProjectName).dll"
    />    
  </Target>  
</Project>  
```

【问题讨论】:

  • 您是否故意以这种方式创建 csproj 而不是使用 dotnet new 模板?
  • 是的,我正在尝试提供一个 csproj 文件并通过它控制构建。
  • 但是 csproj 文件不是典型的 csproj 文件的样子,因为您可能会丢失很多 csc 任务的输入。您可以使用更高的日志级别进行构建吗? (例如-flp:verbosity=diag 生成 msbuild.log)
  • 我可以通过更改 csproj 文件内容来解决它。谢谢。

标签: .net msbuild .net-core


【解决方案1】:

当我尝试从 VS Code 而不是 Visual Studio(macOS 环境)构建我的项目时,我遇到了这个问题。 经过一些不成功的研究,我只是删除了对Microsoft.Net.Compilers的引用

删除它后,我可以从 VS Code 和 Visual Studio for MAC 运行、构建和调试。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    • 2019-02-04
    • 2012-10-18
    • 2020-06-19
    • 2013-02-28
    • 1970-01-01
    相关资源
    最近更新 更多