.NET Core CLI and MSBUILD Cheat Sheet

This is a small .NET Core CLI and MSBUILD Cheat Sheet with the list of commands and settings I use almost on daily basis when working with .NET Core, the command line and Visual Studio Code.

Checks

Check installed CLI version:

1dotnet --version

Show available templates:

1dotnet new

Solutions

Create a solution with the name of current the folder:

1dotnet new sln

Create a solution with a specific name:

1dotnet new sln --name [solution name]

Add a project to a solution:

1dotnet add sln [relative path to csproj file]

Packages

Add package reference to the project in the current folder:

1dotnet add package [package name]

Remove a package reference from the project in the current folder:

1dotnet remove package [package name]

Add a specific package version reference to the project in the current folder:

1dotnet add package [package name]-v [version]

Restore packages:

1dotnet restore

Create a nuget package for the project in current folder:

1dotnet pack

Project Templates

Install a new project template:

1dotnet new --install [dotnet template name]

Remove a project template:

1dotnet new --uninstall [dotnet template name]

Run test defined in current folder project

1dotnet test

Builds

Build current’s folder solution or project

1dotnet build

Build current’s folder solution or project with release configuration

1dotnet build -c Release

Publish artifacts for current’s folder solution or project.

1dotnet publish 

MSBUILD

To add a reference to a local assembly without nuget package, edit your csproj and add a Reference as shown in the following sample:

1<code>
2  <ItemGroup>
3    <Reference Include="[Relative path to the Assembly dll file]" />
4  </ItemGroup>
5</code>

Force a file to be copied to the output folder, edit your csproj and add a Content section as shown in the following sample:

1<code>
2 <ItemGroup>
3  <Content Include="[name of the file]">
4   <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
5  </Content>
6 </ItemGroup>
7</code>

Hope it helps!


Toggle Raspberry Pi GPIO Pins with ASP.NET Core 2.0
Use PowerShell to Enable Azure Analysis Services Firewall
comments powered by Disqus