Skip to main content

3 posts tagged with ".NET"

View all tags

Summary of frequently used dotnet commands

· One min read
CommandFunction
dotnet newCreate a new project
dotnet addAdd a package
dotnet removeRemove a package
dotnet publishPublish an app to a directory
dotnet runRun the project
dotnet slnManage solution files

dotnet new

Example

dotnet new wpf

dotnet add

Example

dotnet add package Microsoft.Web.WebView2

dotnet remove

Example

dotnet remove package Microsoft.Web.WebView2

How to install .NET on Ubuntu (including WSL2)

· One min read

Reference: Install .NET on Linux without using a package manager - .NET | Microsoft Learn

Download the install script

wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh

Make the install script executable

chmod +x ./dotnet-install.sh

Install the dot.net SDK

./dotnet-install.sh

To install the latest version

./dotnet-install.sh --version latest

Add to path

Open $HOME/.bashrc and add the following:

export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools

Function to return MD5 (string) from string (C#)

· One min read

Functions used

  • byte[] Encoding.UTF8.GetBytes(string) Converts a string to a byte[]
  • MD5 MD5.Create() Creates an MD5 instance
  • byte[] md5.ComputeHash(byte[]) Generates an MD5 hash from a byte[]

Example

string str2MD5(string src)
{
byte[] srcBytes = Encoding.UTF8.GetBytes(src);
string MD5src;
using (MD5 md5 = MD5.Create())
{
byte[] MD5srcBytes = md5.ComputeHash(srcBytes);
StringBuilder sb = new();
for (int i = 0; i < MD5srcBytes.Length; i++)
sb.Append(MD5srcBytes[i].ToString("x2"));
MD5src = sb.ToString();
}
return MD5src;
}