Build .NET solutions/projects using cake 2

Cake is a powerful tool that implements build functionality for various .NET solutions. It can extend your build with custom parameters and values that you want to reference on a CI/CD pipeline or in your metadata. In this article I will demonstrate how to use cake in order to build your .NET solution.

First create a Console App or another .NET solution that you want to build.

create a new console application

For this demonstration I will use the default template that is provided from cake website. You should rename and point to your solution name, in my case the solution is named ConsoleApp1.

The default build script includes three tasks.

  • The first one cleans output of previous builds.
  • The second one will build your application
  • The third will run .net tests.

In the build script provided below, I have provided as configuration Debug. You can change this value on the configuration line.

var target = Argument("target", "Build");
var configuration = Argument("configuration", "Debug");

//////////////////////////////////////////////////////////////////////
// TASKS
//////////////////////////////////////////////////////////////////////


Information("Beginning cleaning application.....");
Task("Clean")
    .WithCriteria(c => HasArgument("rebuild"))
    .Does(() =>
{
    CleanDirectory($"./bin/{configuration}");
});

Information("Beginning building application.....");

Task("Build")
    .IsDependentOn("Clean")
    .Does(() =>
{
    DotNetCoreBuild("./ConsoleApp1.sln", new DotNetCoreBuildSettings
    {
        Configuration = configuration,
    });
});


Information("DotNetCoreTest task .....");

Task("Test")
    .IsDependentOn("Build")
    .Does(() =>
{
    DotNetCoreTest("./ConsoleApp1.sln", new DotNetCoreTestSettings
    {
        Configuration = configuration,
        NoBuild = true,
    });
});

//////////////////////////////////////////////////////////////////////
// EXECUTION
//////////////////////////////////////////////////////////////////////

RunTarget(target);

In order to build you should place the above file on your solution directory with the name build.cake. Then you will have to run dotnet cake and the build will run.

build output

https://cakebuild.net/

Bad HTTP response returned from server Code 500 – Ansible authentication

When you try to connect through kerberos with a domain account on Ansible windows hosts, you may encounter the error that is shown below:

The configuration for the kerberos connection. is listed below, and you can find the steps on my previous article.

[all:vars]

ansible_connection = winrm
ansible_winrm_server_cert_validation = ignore
ansible_port =  5985
ansible_user = domainUser
ansible_password = password
ansible_become_method= runas
ansible_winrm_transport = kerberos

The problem occur while trying to connect with port 5985 unencrypted on the remote machine. To bypass the problem you could run on PowerShell the below command which allows an unencrypted connection through winrm protocol.

Set-Item -Path WSMan:\localhost\Service\AllowUnencrypted -Value true

Lastly you could try a test connection to verify the result.

Allow non Admin users to connect through RDP on domain controller

On domain controllers only domain administrator users are allowed to initiate a remote desktop connection and connect successfully. In order to allow normal domain users to connect through RDP perform the below:

run local group policy editor on each domain controller

Go under Windows Settings -> Security Settings -> User Rights Assignment

edit allow log on through Remote Desktop services policy and add a user or group.

The last step is to add the above user or group to remote desktop users group on Active Directory Users and Computers -> Builtin -> Remote Desktop Users

Clients cannot registered to WSUS console

Recently I faced an issue with Microsoft’s WSUS update manager and the console on which clients are reporting. In more detail although clients were able to connect and communicate with WSUS server, they could not be registered on the console.

I tried many workarounds that I found online but non of them worked. By troubleshooting further I was able to detect the issue.

First things first, when you deal with such an issue try ping in order to verify network connectivity and also

Test-NetConnection WSUS_serverIP -port 80 
Test-NetConnection WSUS_serverIP -port 8530 (or 8531 for encrypted)

If you are sure that network and port connectivity is in place run the below powershell command which will generate a log output on your desktop. Try to read the logs and verify the issue.

Get-WindowsUpdateLog

On my case the issue was a proxy that did not allow communication to WSUS web service which performs the necessary tasks in order for the machine to be registered on the console.

Below is the command to reset web proxy settings on a windows server 2016 machine.

Bonus content:

After the successful removal of proxy I restarted the windows update setting and it got stuck on a server with the state of stopping.

You can kill a stuck service on Windows with the below command on an elevated prompt:

taskkill /F /FI "SERVICES eq wuauserv"

I used wuauserv as it is the name of windows update service