dotnet new
command to create a new solution golden.sln inside a new folder named golden:dotnet sln
command to add the newly created library.csproj project to the solution:Newtonsoft.Json
NuGet package. The dotnet add
command adds new items to a project. To add a reference to a NuGet package, use the dotnet add package
command and specify the name of the package:Newtonsoft.Json
and its dependencies to the library project. Alternatively, manually edit the library.csproj file and add the following node:dotnet restore
, (see note) which restores dependencies and creates an obj folder inside library with three files in it, including a project.assets.json file:Thing
class contains one public method, Get
, which returns the sum of two numbers but does so by converting the sum into a string and then deserializing it into an integer. This makes use of a number of modern C# features, such as using static
directives, expression-bodied members, and string interpolation.dotnet build
command. This produces a library.dll file under golden/library/bin/Debug/netstandard1.4:dotnet add reference
command:Assert.NotEqual
), which will fail. An important step in building unit tests is to create the test to fail once first to confirm its logic.Assert.NotEqual
to Assert.Equal
. Execute the following command from the golden folder to re-run the test, which passes this time:dotnet add reference
command:dotnet restore
(see note) to restore the dependencies of the three projects in the solution. Open Program.cs and replace the contents of the Main
method with the following line:using
directives to the top of the Program.cs file:dotnet run
command to run the executable, where the -p
option to dotnet run
specifies the project for the main application. The app produces the string 'The answer is 42'.WriteLine
statement in the Main
method. Do this by either pressing the F9 key when the cursor is over the WriteLine
line or by clicking the mouse in the left margin on the line where you want to set the breakpoint. A red circle will appear in the margin next to the line of code. When the breakpoint is reached, code execution will stop before the breakpoint line is executed.Get
method and make sure that you have passed in the correct arguments. Confirm that the answer is 42.dotnet restore
because it's run implicitly by all commands that require a restore to occur, such as dotnet new
, dotnet build
and dotnet run
.It's still a valid command in certain scenarios where doing an explicit restore makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control the time at which the restore occurs.