Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins fail to build C# project

I'm trying to build from jenkins a Vistual Studio 2017 solution containing 2 projects: ASP.NET and Test projects.

Please tell me if you need more details.

Configurations:

enter image description here

enter image description here

The errors in the console output:

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly C:\Program Files (x86)\Jenkins\workspace\new 3\packages\Microsoft.Net.Compilers.2.1.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj]

C:\Program Files (x86)\Jenkins\workspace\new 3\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props(13,5): error : Microsoft.Net.Compilers is only supported on MSBuild v14.0 and above [C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj]

Full console output:

Started by user stav alfi Building in workspace C:\Program Files (x86)\Jenkins\workspace\new 3

git.exe rev-parse --is-inside-work-tree # timeout=10 Fetching changes from the remote Git repository git.exe config remote.origin.url https://github.com/stavalfi/c_sharp_example_project.git # timeout=10 Fetching upstream changes from https://github.com/stavalfi/c_sharp_example_project.git git.exe --version # timeout=10 git.exe fetch --tags --progress https://github.com/stavalfi/c_sharp_example_project.git+refs/heads/:refs/remotes/origin/ git.exe rev-parse "refs/remotes/origin/master^{commit}" # timeout=10 git.exe rev-parse "refs/remotes/origin/origin/master^{commit}" # timeout=10 Checking out Revision a70858995d5557ae1483965072e2a66833f9979d (refs/remotes/origin/master) git.exe config core.sparsecheckout # timeout=10 git.exe checkout -f a70858995d5557ae1483965072e2a66833f9979d Commit message: "Add project files." git.exe rev-list a70858995d5557ae1483965072e2a66833f9979d # timeout=10 [new 3] $ cmd /c call C:\WINDOWS\TEMP\jenkins5187263831491564261.bat

C:\Program Files (x86)\Jenkins\workspace\new 3>nuget restore MSBuild auto-detection: using msbuild version '15.3.409.57025' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. All packages listed in packages.config are already installed.

C:\Program Files (x86)\Jenkins\workspace\new 3>exit 0 Path To MSBuild.exe: C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe Executing the command cmd.exe /C " chcp 1252 && C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /p:VisualStudioVersion=12.0 WebApplication2.sln " && exit %%ERRORLEVEL%% from C:\Program Files (x86)\Jenkins\workspace\new 3 [new 3] $ cmd.exe /C " chcp 1252 && C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /p:VisualStudioVersion=12.0 WebApplication2.sln " && exit %%ERRORLEVEL%% Active code page: 1252 Microsoft (R) Build Engine version 4.7.2053.0 [Microsoft .NET Framework, version 4.0.30319.42000] Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch. Build started 04/10/2017 19:16:39. Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.sln" on node 1 (default targets). ValidateSolutionConfiguration: Building solution configuration "Debug|Any CPU". Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.sln" (1) is building "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj" (2) on node 1 (default targets). Project file contains ToolsVersion="15.0". 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="4.0". For more information, please seehttp://go.microsoft.com/fwlink/?LinkId=291333. GenerateTargetFrameworkMonikerAttribute: Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files. C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly C:\Program Files (x86)\Jenkins\workspace\new 3\packages\Microsoft.Net.Compilers.2.1.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj]Done Building Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj" (default targets) -- FAILED. Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.sln" (1) is building "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.Tests\WebApplication2.Tests.csproj" (3) on node 1 (default targets). Project file contains ToolsVersion="15.0". 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="4.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=291333. Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.Tests\WebApplication2.Tests.csproj" (3) is building "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj" (2:2) on node 1 (default targets). Project file contains ToolsVersion="15.0". 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="4.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=291333. C:\Program Files (x86)\Jenkins\workspace\new 3\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props(13,5): error : Microsoft.Net.Compilers is only supported on MSBuild v14.0 and above [C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj] Done Building Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj" (default targets) -- FAILED. Done Building Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.Tests\WebApplication2.Tests.csproj" (default targets) -- FAILED. Done Building Project "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.sln" (default targets) -- FAILED.

Build FAILED.

"C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.sln" (default target) (1) -> "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj" (default target) (2) -> (CoreCompile target) -> C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Microsoft.CSharp.targets(316,9): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly C:\Program Files (x86)\Jenkins\workspace\new 3\packages\Microsoft.Net.Compilers.2.1.0\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Could not load file or assembly 'Microsoft.Build.Utilities.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj]

"C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.sln" (default target) (1) -> "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2.Tests\WebApplication2.Tests.csproj" (default target) (3) -> "C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj" (default target) (2:2) -> (ValidateMSBuildToolsVersion target) -> C:\Program Files (x86)\Jenkins\workspace\new 3\packages\Microsoft.Net.Compilers.2.1.0\build\Microsoft.Net.Compilers.props(13,5): error : Microsoft.Net.Compilers is only supported on MSBuild v14.0 and above [C:\Program Files (x86)\Jenkins\workspace\new 3\WebApplication2\WebApplication2.csproj]

0 Warning(s)
2 Error(s)

Time Elapsed 00:00:00.37 Build step 'Build a Visual Studio project or solution using MSBuild' marked build as failure Finished: FAILURE

like image 810
Stav Alfi Avatar asked Jan 29 '23 11:01

Stav Alfi


2 Answers

The important error message is already logged by the package itself:

Microsoft.Net.Compilers is only supported on MSBuild v14.0 and above

You are using the msbuild version distributed with .NET Framework, which is an old version (v4). Use the path to the version distributed with VS 2017 / Build Tools for VS 2017 which should be like

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe

(replace Enterprise with the version of VS / Build Tools you have installed on the server)

like image 132
Martin Ullrich Avatar answered Feb 02 '23 07:02

Martin Ullrich


The error

Microsoft.Net.Compilers is only supported on MSBuild v14.0 and above

is very telling. You are trying to use a Nuget C# compiler (likely C# 7) but support for Nuget compilers was introduced in VS 2015 (MSBuild 14). You need to have your Jenkins project use that version of MSBuild or greater.

If you have access to the build slave; the easiest way to get there is to just install the community edition of Visual Studio 2015 or greater on it and point to the installation's MSBuild.

like image 33
BradleyDotNET Avatar answered Feb 02 '23 09:02

BradleyDotNET