Jenkins unable to build C#6 features until second execution - c#

I've got a .Net application being built by Jenkins Pipelines and jenkinsfile. My Jenkins installation (up to date on the LTS versions) is unable to build my .Net application the first time within a workspace. Any new branch creates a new workspace then fails to build:
"<JENKINS_WORKSPACE_FOR_BRANCH\src\MY_SOLUTION.sln" (default target) (1) ->
"<JENKINS_WORKSPACE_FOR_BRANCH\src\Core\MySln.Core.csproj" (default target) (2) ->
(CoreCompile target) ->
Configuration\DefaultConfiguration.cs(143,51): error CS1002: ; expected [<JENKINS_WORKSPACE_FOR_BRANCH\src\Core\MySln.Core.csproj]
Configuration\DefaultConfiguration.cs(143,54): error CS1520: Method must have a return type [<JENKINS_WORKSPACE_FOR_BRANCH\src\Core\MySln.Core.csproj]
Configuration\DefaultConfiguration.cs(143,66): error CS1031: Type expected [<JENKINS_WORKSPACE_FOR_BRANCH\src\Core\MySln.Core.csproj]
Model\User.cs(48,24): error CS1056: Unexpected character '$' [<JENKINS_WORKSPACE_FOR_BRANCH\src\Core\MySln.Core.csproj]
Model\User.cs(75,20): error CS1056: Unexpected character '$' [<JENKINS_WORKSPACE_FOR_BRANCH\src\Core\MySln.Core.csproj]
Line 143 is
public string MyProperty=> ConfigValue("MyProperty");
Using the new C# 6 Expression Bodied Function Members syntax. The unexpected Character '$' is the c# 6 string formatting syntax:
var mystring = $"This is where I'll put {thisProperty} in my string";
My build call is:
bat "\"${tool 'MSBuildPipeline'}\" src\\MY_SOLUTION.sln /p:Configuration=Release /p:PlatformTarget=x64 /p:ProductVersion=1.3.5.${env.BUILD_NUMBER} /p:VisualStudioVersion=12.0 /p:TargetFrameworkVersion=v4.5 /ToolsVersion:12.0 /p:FrameworkOverride=\"C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.5\""
Which used to be much simpler but I've been trying to specify more and more to get to the bottom of this. I'm using MSBuild 12. I attempted to use MSBuild 14 but there's a problem with building on MSBuild 14 where you need to install a Windows 10 SDK to enable license generation and the SDKs only exist for .Net versions 4.6.x. I've got the Microsoft.Net.Compilers 1.3.2 NuGet packages installed to help enable the c# 6 syntax. The new 2.0.1 version only supports MSBuild 14.0+.
Again, it will only error out for the first build in this workspace. If I hit build again it will succeed without issue, despite no code changes. I'm assuming it's pulling some sort of .dll or asset the first time which fixes the issue for subsequent builds but I don't know what.

Related

DevOps build reporting IDE0055 errors, while local build does not

I'm using a few .csproj features:
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Locally, this all works fine.
Cause a warning, it won't build
Format something in non-standard way, it won't build
The issue is: it builds fine locally, but Azure DevOps fails, citing IDE0055 for in-line comments on chained methods:
var list = new List<string>();
var cleanList = list
// ignore zero-length strings
.Where(l => l.Length == 0)
// ignore too-long strings
.Where(l => l.Length > 10)
.ToList();
There are two differences:
Local: Windows and MSBuild version 17.4.0+18d5aef85 for .NET
DevOps: Linux and Build Engine version 17.1.1+a02f73656 for .NET
I'm assuming this outdated (?) build engine is to blame. Is there a way to target a different build engine? Hopefully it's not tied to UseDotNet#2 packageType, as that needed to be set to 6.0.202 so the code could run on AWS Lambda.
The full DevOps output:
Starting: Build projects
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.210.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
/opt/hostedtoolcache/dotnet/dotnet build /home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" -c Release -r linux-x64 -p:PublishReadyToRun=true
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored /home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj (in 367 ms).
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(22,33): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(22,33): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(23,46): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(23,46): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(24,43): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(24,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(25,43): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(25,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
Build FAILED.
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(22,33): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(23,46): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(24,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(25,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
0 Warning(s)
4 Error(s)
Time Elapsed 00:00:03.50
##[error]Error: The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
/opt/hostedtoolcache/dotnet/dotnet build /home/vsts/work/1/s/Psrm.ScheduleCalculator.InternalContract/Psrm.ScheduleCalculator.InternalContract.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" -c Release -r linux-x64 -p:PublishReadyToRun=true
Based on your description, the problem looks like is related to the different OSs (Windows and Linux) where the build is running.
Since you develop and edit the C# code on your local Windows machine, it can match the consistent code style when you directly build the code on the local Windows machine.
However, when you move to the Linux machine to build, for how indentation, spaces, and new lines are aligned around .NET programming language constructs, it may be different with Windows.
For more details about the IDE0055 Error, you can reference the document "Formatting rule (IDE0055)".
For your case, you can try to select a Windows agent to run the build pipeline on Azure DevOps. We have provided the Microsoft-hosted Windows agents (windows-2022 and windows-2019) for Azure Pipelines on Azure DevOps. Or you can set up a self-hosted agent on your local Windows machine to run the build pipeline.

Can i build C# projects on Ubuntu with Jenkins?

We have Jenkins running on an Ubuntu OS 18.04.01 LTS and an older project written in C# / .NET 4.5
The application was always build manually in the past and I would like to use Jenkins to introduce CI so nobody needs to build the project manually anymore. The application does not have to run on Linux or anything like that, we just need the buildfiles (executables and DLL files). Is it possible to build this C# solution with Jenkins on Ubuntu?
I know about MONO and XBUILD but actually I can't manage to build the project under ubuntu because of different issues which do not happen under Windows, e.g. see here:
UserControls/ExpandablePanel.cs(33,35): error CS1043: Invalid accessor body `=>', expecting `;' or `{'
UserControls/ExpandablePanel.cs(33,66): error CS1043: Invalid accessor body `=>', expecting `;' or `{'
UserControls/ExpandablePanel.cs(35,41): error CS1043: Invalid accessor body `=>', expecting `;' or `{'
UserControls/ExpandablePanel.cs(37,40): error CS1043: Invalid accessor body `=>', expecting `;' or `{'
UserControls/ExpandablePanel.cs(133,22): error CS1644: Feature `pattern matching' cannot be used because it is not part of the C# 6.0 language specification
UserControls/PagedDataGridView.cs(441,68): error CS1043: Invalid accessor body `=>', expecting `;' or `{'
1 Warning(s)
6 Error(s)
Is it even possible or do I definitely need to run Jenkins on a Windows machine?
It is possible. You can build C# project on Linux/Ubuntu. Try building using mono. When you will install mono package, one of the binaries that you will get will be xbuild. To build just invoke the following command:
xbuild <path to csproj/solution file>
Try building this manually first and then integrate with jenkins.

Getting error while running SonarScannerMSBuild on Xamarin projects

1) When I Try to use Rebuild option
MANOJs-MacBook-Air:UI_Testing2 manojdeshpande$ mono /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/MSBuild.SonarQube.Runner.exe /t:Rebuild
WARNING: ------------------------------------------------------------------------
This executable is deprecated and may be removed in next major version of the SonarScanner for MSBuild. Please use 'SonarScanner.MSBuild.exe' instead.
SonarScanner for MSBuild 4.5
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml
Loading analysis properties from /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml
WARNING: Please specify the command 'begin' or 'end' to indicate whether pre- or post-processing is required. These parameters will become mandatory in a later release.
Pre-processing started.
Preparing working directories...
05:23:39.463 05:23:39.454 Unrecognized command line argument: /t:Rebuild
05:23:39.464 05:23:39.462 A required argument is missing: /key:[SonarQube project key]
05:23:39.464 Expecting at least the following command line argument:
SonarQube project key
When connecting to a SonarQube server earlier than version 6.1, the following command line arguments are also required:
SonarQube project name
SonarQube project version
The full path to a settings file can also be supplied. If it is not supplied, the exe will attempt to locate a default settings file in the same directory as the SonarQube Scanner for MSBuild.
Use '/?' or '/h' to see the help message.
05:23:39.464 Pre-processing failed. Exit code: 1
2) I get some other error with authentication problems. Any work around this.
MANOJs-MacBook-Air:UI_Testing2 manojdeshpande$ mono /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarScanner.MSBuild.exe begin /k:"Xamarin" /d:sonar.host.url="http://localhost:9000" /d:sonar.login="token1"
SonarScanner for MSBuild 4.5
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml
Loading analysis properties from /Users/manojdeshpande/Downloads/sonar-scanner-msbuild-4.5.0.1761-net46/SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories...
05:18:52.798 Updating build integration targets...
05:18:52.833 Fetching analysis configuration settings...
05:18:52.94 Failed to request and parse 'http://localhost:9000/api/settings/values?component=Xamarin': The remote server returned an error: (401) .
05:18:52.94 Could not authorize while connecting to the SonarQube server. Check your credentials and try again.
05:18:52.941 Pre-processing failed. Exit code: 1

ERROR: XXX.cs can't be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files

We've upgraded our SonarQube instance to 6.7 version and since then we see a project failing with below error during SonarQube analysis from VSTS build.
ERROR: Error during SonarQube Scanner execution ERROR: File
src/Platform/DeviceProvisioning/Business.Contracts/Models/DeviceDetailsForReplication.cs
can't be indexed twice. Please check that inclusion/exclusion patterns
produce disjoint sets for main and test files ERROR: ERROR: Re-run
SonarQube Scanner using the -X switch to enable full debug logging.
The SonarQube Scanner did not complete successfully
However the same project gets analyzed without any issue in our SonarQube 6.1 instance. To check if the issue is with test file inclusion settings, i tried creating a new SonarQube project with no explicit setting for inclusion\exclusion but i still get the same error on a new project.
Can someone let me know how we can fix the issue.

How to make MSBUILD resolve System.Action<T1,T2> correctly?

My projects build fine in Visual Studio and also using MSBUILD on my machine.
On the build agent however if I run MSBUILD I get the error below.
I have already tried to specify a target framework of 4.0 but without success.
Any other ideas?
"c:\Test\Test.csproj" (default target) (6) ->
(CoreCompile target) ->
ItemSearchDelegate.cs(17,10): error CS0433: The type 'System.Action<T1,T2>' exists in both 'c:\Windows\Microsoft.NET\
Framework\v4.0.30319\mscorlib.dll' and 'c:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.
dll'
What I find most interesting: some lines above that error from MSBUILD, I see:
CSC : warning CS1685: The predefined type 'System.Action' is defined in multiple assemblies in the global alias; using definition from 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\mscorlib.dll'
So it decides to use v4 just to complain a second later?
All I do is: open the command line at the location of the .CSPROJ file and run "msbuild". Nothing fancy.

Categories

Resources