HelloWorld in .Net Core really takes less than 10 minutes!

Intro

I have been paying attention to the development of the .NET Core framework and the great features coming out of it. Things like cross-platform compatibility are very appealing and open a whole new window of opportunities to the developer community. I never decided to start experimenting with this until now, and since I saw how easy it was to setup, I decided to share my experience here. In this post I will list the required steps to write a HelloWorld console application using .NET Core framework. It literally took me less than 10 minutes to see “Hello World” in the output window!

Steps to create HelloWorld console application in .NET Core

1. Go to dot.net and download the .NET Core SDK

– Download and install .NET Core SDK for Windows
I am using Windows, but the same steps can be applied to Mac and Linux.

2. Open a command line

c:\Users\luis.carrazana\Documents>
I like Windows PowerShell, but you could use the windows command line, or Terminal if using a Mac.

3. Check if .NET Code SDK was successfully installed

Execute the following command:

c:\Users\luis.carrazana\Documents> dotnet
You should see something like this:
dotnetcore

4. Create a folder for the project and navigate to it

c:\Users\luis.carrazana\Documents> cd "MyProjects"
c:\Users\luis.carrazana\Documents\MyProjects> md "DotNetCore101"
c:\Users\luis.carrazana\Documents\MyProjects> cd "DotNetCore101"
c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101>

5. Create a new project

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet new
Two files should be created:
Program.cs  (contains the program logic).
project.json  (contains project configuration, including dependencies).
DotNetCore-dir.PNG
This is the simplest boilerplate for a console application, and it contains the required logic to print “Hello World” to the console.

6. Restore dependencies and prepare the project for execution

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet restore
DotNetCore_restore.PNG
This step generates a new file: project.lock.json
This file should not be touched or checked into source control. Its purpose is to cache the result of analyzing project dependencies, so it is faster the next time. More details abut this file here.

7. Run the program

Execute the following command:

c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> dotnet run
The logic should get executed and the “Hellow World” message should be displayed.
dotnetcore-helloworld

That’s it! You have a full .NET Core program running.

Editing the program

The steps above are useful for setting up the minimal required infrastructure to execute .NET Core logic. From this point, you will certainly want to start choosing developer tools that will allow you to write code in a very efficient way.
You can choose any text editor (including Notepad), or you may wanna choose a more robust IDE to make the development workflow more efficient. Coming from a pure .NET background, my immediate choice is the lightweight Visual Studio Code, which offers some nice integrations and can be executed in Windows, Mac and Linux.
So to edit and extend this program, I would manually open Visual Studio Code and load the project folder. However, I learned a very useful tip from Scott Hanselman in one of his training videos: from the command line, type “code .” and it will open Visual Studio Code with the current folder already loaded, ready to go. Pretty neat.
c:\Users\luis.carrazana\Documents\MyProjects\DotNetCore101> code .

Summary

This post described the required steps to provision and execute a quick console application using .NET Core. This framework is currently in Preview mode, and any developer can start using it to write code and run it on any platform. Being a Consultant working for big enterprises, I don’t see myself leveraging this framework for production in the near future. However, it is a good idea to pay attention to the great amount of innovation coming out of it. This is opening up a whole new world for writing great applications.

Reference

Advertisements

Toolset for a Software Developer

Intro

The following list shows some of the tools I have used (and still do) on my daily activities as a Software Developer.

Password Management

Task & Time Management

Online Storage

  • Google Drive
  • OneDrive
  • DropBox

Software Development

  • Visual Studio
  • Visual Studio Code
  • Visual Studio Online
  • SQL Management Studio
  • PowerShell

Continuous Integration

Virtualization

Training

Brainstorming

Prototyping

  • Balsamic
  • PowerPoint Story Board
  • Microsoft Visio

Project Management

  • Visual Studio Online
  • Microsoft TFS
  • Trello

Team Work / Collaboration

 

 

 

How to start doing TDD?

Intro

A colleague recently asked my advice about how to start incorporating Test-Driven Development (TDD) into his project. I don’t consider myself very advanced in this topic, but long ago I recognized the tremendous value of this development approach and the benefits it provides for writing good and clean software, therefore I started practicing it and forming my own learning path. Rather than jumping right into a demo, I decided to provide a set of initial pointers that will allow any developer to better understand and apply this development paradigm, even before writing a line of code.

What to learn before writing unit tests?

Here are some of the topics along with useful resources that will allow developers better understand and apply the TDD approach:

  • Understand how to write testable code
  • Learn the art of refactoring
  • Understand the TDD philosophy
    • What is Red->Green->Refactor workflow?
  • Try and choose a unit test framework that works for you and learn the syntax
  • Define a naming convention for your tests
    • Setting a naming convention is very important, since the number of test cases will grow exponentially as you write more code, and you want a quick way to identify what scenarios are being tested and what is breaking, just by glancing over the list of tests.
    • For test libraries, I like to use:
      • <libraryname>.tests.dll
    • For test methods, I like to use:
      • <classname>_<methodname>_<testconditions>_<expectedresult>
  • Practice, practice, practice
    • Exercism.com – I found this amazing site offering several simple exercises that must be solved using a TDD approach and can be implemented in multiple languages. Great resource not only for learning TDD, but also for keeping programming and logical skills sharp and learning a new language once in a while. It is also great to be able to view how other programmers implement the same solution, as well as providing and receiving feedback. I took the personal challenge of solving a couple of exercises every week.

Once you are very familiar with the above topics, you could try expanding into more adavanced scenarios:

  • Learn how to use mocks and fakes
  • Integrate unit tests into the Continuous Integration build
  • Get test coverage reports

Summary

I hope this post can be helpful to those developers wanting to incorporate TDD into their development approach for the first time. It only touches the surface, but hopefully it can serve as a starting point for future craftsmen, willing to put the extra effort in order to write clean, efficient and maintainable code.
Please let me know if you’d like to expand on any topic or add new ones to this list.

Reference

Setup SharePoint 2013 Single Server Environment – Part 4: SQL Server setup

Intro

This series describes the details and required steps for setting up a SharePoint 2013 Single Server Environment. This is typically used by developers in order to write custom solutions without interfering with one another. This type of environment is also is good for evaluation, training and demonstration purposes.
The series contains 6 parts:
  1. Environment Details
  2. VM setup
  3. Windows Server 2012 setup
  4. SQL Server setup
  5. SharePoint Installation and Initial Configuration
  6. Post-Installation Steps

SQL Server setup

This article contains the required steps to properly setup the SQL Server environment to properly run a single server SharePoint 2013 environment.

Install SQL Server 2012 Features

As per the previous article in this series, we should have downloaded the SQL Server 2012 ISO installation file and added it to the VM as a Virtual Optical Drive by now.
  1. From the virtual drive containing SQL installation, Run SETUP.EXE
  2. Select at least the following Core Features:
    1. Database Engine Services
    2. Management Tools – Basic
    3. Management Tools – Complete
  3. Select additional features based on specific needs

Setup Max Degrees of parallelism

Update the following PowerShell script, specifying the appropriate server instance.

#### Set MDOP to 1
Import-Module "sqlps" -DisableNameChecking
$sql = "EXEC sys.sp_configure N'show advanced options', N'1' RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'max degree of parallelism', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
EXEC sys.sp_configure N'show advanced options', N'0' RECONFIGURE WITH OVERRIDE
GO"
Invoke-Sqlcmd -Query $sql [-ServerInstance "SERVER\instance"]

Open a PowerShell console with administrator credentials and execute the above script.

Note: If you are unable to execute PowerShell commands on the server, you may need to change the execution policy. See this link for reference. 

Delegate Permissions

  1. Open SQL Management Studio
  2. Create SQL Login for sp_admin service account
  3. Assign server roles:
    1. dbcreator
    2. securityadmin

 

<< Windows Server 2012 Setup SharePoint Installation & Config..>>

 Reference

Using the Set-ExecutionPolicy Cmdlet in PowerShell

 

Setup SharePoint 2013 Single Server Environment – Part 3: Windows Server 2012 Setup

Intro

This series describes the details and required steps for setting up a SharePoint 2013 Single Server Environment. This is typically used by developers in order to write custom solutions without interfering with one another. This type of environment is also is good for evaluation, training and demonstration purposes.
The series contains 6 parts:
  1. Environment Details
  2. VM setup
  3. Windows Server 2012 setup
  4. SQL Server setup
  5. SharePoint Installation and Initial Configuration
  6. Post-Installation Steps

Windows 2012 Server setup

This article contains the required steps to properly setup Windows Server 2012 with the required features to run a single server SharePoint 2013 environment, which includes setting Active Directory and Domain Controller.

Windows Server 2012 Installation

As per the previous article in this series, we should have downloaded the Windows Server 2012 ISO installation file and added it to the VM as a Virtual Optical Drive by now. When the VM is started, the Windows installation will kick in automatically.

Configure Server Roles

After the Windows installation is complete, follow this steps to properly add the required server roles and features:
  1. Setting Computer Name and Network Settings
    1. From the Server DashBoard go to Local Server
    2. Change Computer Name and Restart
    3. After restart, select Ethernet > Properties > Internet Protocol Version 4
    4. Specify network settings such as:
      1. IP address: 192.168.100.10,
      2. Subnet mask: 255.255.255.0,
      3. Subnet Gateway: 192.168.100.1
  2. Adding Server Roles
    1. From the Server Manager DashBoard click Add Roles and Features
    2. Set Installation Type to Role-Based or Featured-Based installation
    3. Under Server Roles, select Active Directory Domain Services
    4. Accept popup with required features
    5. Leave everything else as default and click through the end of the wizard
  3. Promote Server to Domain Controller
    1. Go to Server Manager > AD DS
    2. There should be a warning message on top displaying “Configuration required for Active Directory …”. Click More…
    3. On All Server Task Details click “Promote this server to a domain…”
    4. Under Deployment Configuration, select “Add a new forest” and specify the domain name
    5. Enter Administrator password
    6. Leave everything else as default and click through the end of thee wizard
    7. Computer will be restarted at the end
  4. Add users to Domain Controller
    1. After restart, open Active Directory Users and Computers
    2. Under Users, add all required accounts (tick “User cannot change password” and “Password never expires” options):
      1. sp_admin
      2. sp_instal
    3. Add sp_admin to the local “Administrators” group
  5. Install .NET 3.5 Features as prerequisite for SQL Server features installation
    1. From Server Manager > DashBoard click “Add roles and features”
    2. From Features tab select “.Net Framework 3.5 Features”
    3. Click through the end of the wizard.

 

<< VM Setup SQL Server Setup >>

Setup SharePoint 2013 Single Server Environment – Part 2: VM Setup

Intro

This series describes the details and required steps for setting up a SharePoint 2013 Single Server Environment. This is typically used by developers in order to write custom solutions without interfering with one another. This type of environment is also is good for evaluation, training and demonstration purposes.

The series contains 6 parts:

  1. Environment Details
  2. VM setup
  3. Windows Server 2012 setup
  4. SQL Server setup
  5. SharePoint Installation and Initial Configuration
  6. Post-Installation Steps

VM setup

This article describes the steps to create a virtual machine using Virtual Box. It also assumes that a MSDN subscription is available in order to download the required software installation.

  1. Get the software installations from MSDN
    • Windows Server 2012 (64-bit)
    • SQL Server 2012
    • SharePoint 2013 Server
  2. Download and Install Virtual Box
  3. Create a new VM
  4. Assign the following parameters:
    • Type: Microsoft Windows
    • Version: Windows 2012 (64-bit)
    • Memory Size: 8192 MB
    • Hard Disk: Create a virtual hard disk now
    • File Size: 100 GB
    • Hard Disk File Type: VDI (VirtualBox Disk Image)
    • Storage on Physical Hard Disk: Dynamically Allocated
  5. After the VM is created, click Settings from the top menu and set the following from the left menu:
    1. Storage: Add the all the ISO installation files, starting by Windows Server 12
    2. System: Increase the number of processors to 2
    3. Network: On the Adapter 2 tab, select Bridge Adapter and use the current adapter from the host machine

 

<< Environment Details Windows Server 2012 Setup >>

Reference

VirtualBox Site

MSDN Subscriber Downloads

Setup SharePoint 2013 Single Server Environment – Part 1: Environment Details

Intro

This series describes the details and required steps for setting up a SharePoint 2013 Single Server Environment. This is typically used by developers in order to write custom solutions without interfering with one another. This type of environment is also is good for evaluation, training and demonstration purposes.
The series contains 6 parts:
  1. Environment Details
  2. VM setup
  3. Windows Server 2012 setup
  4. SQL Server setup
  5. SharePoint Installation and Initial Configuration
  6. Post-Installation Steps

Environment Details

This article contains the environment details, including hardware requirements, minimum recommended services, minimum software, an required service accounts.

Hardware Requirements

  • Processor: 4 cores, 64-bit
  • RAM: 10GB
  • Hard-Drive Space: 100GB

Minimum Recommended Services for Development Environment

  • App Management Service Application
  • Central Administration Website
  • Claims to Windows Token Service (C2WTW)
  • Distributed Cache Service
  • Microsoft SharePoint Foundation 2013 Site and Subscription Setting Service
  • Secure Store Service
  • User Profile Service Application (SP 2013 only)

Minimum Software

Optional Extra Software

  • Microsoft SharePoint Designer 2013
  • Google Chrome
  • Firefox
  • ULSViewer

Service Accounts

Account Purpose Requirements
SQL Service Account

sp_sql

Used to run SQL Server services:

  • MSSQLSERVER
  • SQLSERVERAGENT
  • Use either a Local System account or a domain user account.
SharePoint Setup Account

sp_admin

Used to run the following:

  • Setup
  • SharePoint Products Configuration Wizard
  • Domain user account.
  • Member of the Administrators group on each server on which Setup is run.
  • SQL Server login on the computer that runs SQL Server.
  • Member of the following SQL Server roles:
    securityadmin
    dbcreator
 Server farm account or database access account

sp_farm

Used to perform the following tasks:

  • Configure and manage the server farm.
  • Act as the application pool identity for the SharePoint Central Administration Web site.
  • Run the Microsoft SharePoint Foundation Workflow Timer Service.
  • Domain user account.
  • Additional permissions are automatically granted for the server farm account on Web servers and application servers that are joined to a server farm.
  • The server farm account is automatically added as a SQL Server login on the computer that runs SQL Server.
  • The account is added to the following SQL Server security roles:
    • dbcreator
    • securityadmin
    • db_owner for all SharePoint databases in the server farm

 

VM Setup >>

Reference

Install and Configure SharePoint 2013
Install SharePoint 2013 on a single server with SQL Server