.Net project static code analysis through Jenkins and SonarQube - c#

What I Need -
Dears - I am in process of creating a Jenkins Job for my .Net Solution. The solution has an ASP.NET web application project and a Winforms Project along with several other class libraries,
As a part of the Jenkins job execution, I would also want to perform Static code analysis for which I would be executing SonarQube runner as 'Pre' and 'Post' Build steps.
What have I done so far -
It is to be noted that, I have already installed all of the tools (Jenkins, SonarQube services) and all of the needed plugins (MSBuild, C#, Javascript, Powershell, SonarQube runner etc.,)
I could see that my job executes successfully. Build is good and SonarQube scanner also ran without any issues.
The problem -
Post successful build and analysis, I am seeing analysis report only for ASP.NET web application project in my SonarQube Dashboard. But I am interested only in the Winforms project.
My build is done through MSBuild.exe and I am pointing to the Solution file. Please note that the Winforms project is my Startup project. But nevertheless I could see that SonarQube runner is picking only ASP.NET project for analysis.
My Question -
If someone could tell me how to get the results of the Winforms project it would be great. Let me know, if I am lacking any bit of information. I can provide them.
Thanks in advance - Happy Coding !!!
EDIT - I don't have any projects in the exclusion list. Just the default test projects.
Attaching my MSBuild default exclusion list.

Related

Dotnet build behaves differently when executed from TeamCity

We're seeing a Lucene.NET analyzer build warning that shouldn't be there when executing dotnet build for one of our ASP.NET Core 3.1 web apps. The strange thing is that this warning seems to happen only when executed with the .NET runner in TeamCity; it (correctly) doesn't happen when running the dotnet build command directly from a PowerShell runner, or from the PowerShell console on the same machine (with the same user account, same folder, same code).
The build warning is actually due to a bug (that was fixed in a later Lucene.NET version) but the point is that we see different behavior.
We have tried running the exact same command that's displayed in the Build Log, including passing the TeamCity-generated RSP file to it. Still, outside of the .NET runner we can't reproduce the warning. We confirmed that the same user account runs the process, uses the same NuGet cache and dotnet.exe (and .NET SDK), runs in the same folder for the same code, with the same parameters.
The only thing we can think of is that somehow the .NET Plugin executes dotnet build differently but in a way that's invisible from the Build Log. However, we are out of ideas what else to try or investigate.
Could you help pinpoint where the difference in the two builds could be? Thank you in advance!
I've previously asked this on the TeamCity forum but didn't get a reply.
We ended up just running dotnet build directly, not using the .NET Runner. It has also cut certain builds' times down drastically (40-50% where there were a lot of build warnings).

SonarQube reports no dependencies, 0 Tangle index, for C# solution with 12K+ classes?

We recently setup SonarQube analysis jobs for our main .Net applications, 6 of them totally 4.4 million lines of code and some 35K+ classes between them. We are getting lots of interesting information but the design analysis does not seem to be working at all. The tangle index is zero for all of projects and when we open up the design tool for any of them we get a list of all the folders/namespaces in the project but none of them have any dependancies on any of the other folders/namespaces.
Any ideas on how to debug this? I looked through the logs but obviously with projects this size, unless I really know what I am looking for, grepping logs is needle-in-haystack work.
This is using SQ 5.1 with the 4.0 version of the C# plugin and v 1.2 of the analysis bootstrapper for VS projects.
even if I do understand that this might be misleading, not having any information about dependencies/librairies/design on C# projects is expected. FYI, in SQ 5.2, all those pages and relating metrics will be dropped, see the following Jira ticket: http://jira.sonarsource.com/browse/SONAR-6553.

Building C# project using jenkins

First of all, im not sure if there is a specific forum thats more suitable for request about Jenkins, but I figured I just post it here.
So, I have this C# project, it right now requires Visual Studio 2015 to build and I would like to automate builds with Jenkins. This is the first time I'm using Jenkins and I was able to set it all up, it fetches the code from the gitlab repository, but right now there is no build action configured. For "fun" i tried to simply make it use a "windows batchfile" as build file and added echo test. Checking the console output it downloads the repository code and then tries to execute the batchfile, result is:
java.io.IOException: Cannot run program "cmd" (in directory "/var/lib/jenkins/workspace/Project"): java.io.IOException: error=2, No such file or directory
This of course makes sense, but I wonder now, is there a way to build a C# project with jenkins on a debian server without resorting to mono or something? I know that people build C++ projects for windows with Jenkins on a linux root, so there has to be some sort of cross compiling possibilities.
If the Visual Studio 2015 is a dealbreaker I can also strap it down to VS13 or even below. Any help is greatly appreciated!
/EDIT
Its probably important to say that Mono is NOT an option. Im using features like WPF that are not available for Mono.
Use Jenkins' MSBuild plugin.
Jenkins.NET is a good blog about using Jenkins in a .NET environment. First post is here.

How do I configure Visual Studio Online to run a custom unit test framework?

I'm trying to make the Visual Studio Online build service run my nSpec tests. I've downloaded the nSpec test adapter (which works fine locally), unzipped the DLLs and uploaded those to a separate TFS repository. I've configured the hosted build controller and set the reference to this repo.
As far as I know this should be sufficient, but my build simply doesn't find any unit tests. If I try to edit the build definition -> Click Process, it downloads custom assemblies it looks like, but it just writes this message to the console:
No assemblies were found in the custom assembly path. The assemblies may not exist or you may not have permissions to read them. Contact your Team Foundation Administrator for more information.
I've tried the same procedure with mSpec as well, but exactly the same happens here. nUnit seems to work though, but if I'm not entirely wrong, that might actually be installed already on hosted build server.
Unfortunately this requires the nSpec plugin to be installed on the build server and the TFS Hosted Build servers and you can only use the plugins provided. I believe that the servers only currently support MSTest, nUnit, and xUnit.
To get this working you will need to create your own custom build server. You can install a build server on Azure and install the tools you need. Then you can run your own build configuration there.

How do I set up an ASP.NET build server?

I want to create an ASP.NET build server for the first time since I've never used it.
Does anyone have a tutorial or resource on how to make an ASP.NET build server?
Or can anyone tell me how it's done?
If by "create" you mean "setup a build server" then I suggest you take a look at TeamCity from JetBrains.
TeamCity is a multi purpose build server and can be used to build ASP.NET projects as well. You can get up and running for free, and its very easy to set up, compared to CruiseControl.Net.
Take a look at MSBuild to see how to do specific ASP.NET build stuff.
MSBuild reference
How to use MSBuild to do ASP.NET compilation (video)
You might need something from the msbuildtasks open source task collection
If you really want to create your own build server from scratch (but why?), I can't help you.
You could make a build server using CruiseControl.NET which can build your project.
CruiseControl.Net Tutorial – Part 1
CruiseControl.Net Tutorial – Part 2
There is no ASP.NET build server as such.
Do you have a one-click build script? If not, you should create that first. Once you are able to run a single command and get a complete build, then it is easy to set up CruiseControl or some other build server.
Given the strength of the build servers out there it's really not sensible to spend any time developing your own.
You will, however, need at the minimum
a one-click build script
a source code repository (e.g. Subversion, TFS, or even [shudder] SourceSafe)
a server to use as a build box (I use a virtual image)
You may also find a one-click deployment script written using something like Powershell to be useful, too.
Note that a very effective alternative to CruiseControl.NET and TeamCity is Hudson. Although it's written in Java it's ridiculously simple to get going with a J2EE server like Tomcat.
The key strength of Hudson is the range the plug-ins, which allow you to monitor most version control systems and then not just build (through MSBuild or even the command line) but also run unit tests, acceptance tests, and so on.
You might look at Web Deployment Projects -- they allow you to build your site and merge all DLLs into a single file, for a fully pre-compiled site. You can use it with MSBuild.
An option on the automation side is Team Foundation Server's (TFS) automated builds. TFS also includes source control, bug tracking and many other features you may or may not need.

Categories