Skip to content
opustecnica edited this page Oct 31, 2021 · 6 revisions

Links/REFs


Using dotnet script from Windows Terminal

This tool can run C# code in the terminal, and is useful for experimenting with C# syntax and libraries.

dotnet tool install -g dotnet-script

Once installation is complete, we can run it by executing the dotnet-script command. We can then type C# code and see the result in the terminal:

Use Ctrl+C to exit.


Add a C# menu option to Windows Terminal

{
    "guid": "{eae0e5d6-8091-4a5e-af17-12b57cff0337}",
    "name": "C#",
    "commandline": "dotnet-script",
    "closeOnExit": "always"
}

Intro to VSCode for C# Developers - From Installation to Debugging

  1. New-Item -Name "VSCodeIntroSolution" -Path "C:\Temp" -ItemType Directory
  2. Set-Location "C:\Temp\VSCodeIntroSolution"
  3. dotnet new sln -n "VSCodeIntroSolution"
  4. dotnet new console -n "IntroUI"
  5. dotnet new classlib -n "IntroLibrary"
  6. dotnet sln VSCodeIntroSolution.sln add (Get-ChildItem */*.csproj).FullName
  7. dotnet add "C:\Temp\VSCodeIntroSolution\IntroUI\IntroUI.csproj" reference "C:\Temp\VSCodeIntroSolution\IntroLibrary\IntroLibrary.csproj"
  8. Set-Location "C:\Temp\VSCodeIntro\IntroUI\"
  9. code -r .
  10. Set-Location "C:\Temp\VSCodeIntro\"
  11. code -r .
  12. Set-Location "C:\Temp\VSCodeIntro\IntroUI\"
  13. dotnet run
  14. C:\Temp\VSCodeIntro\IntroUI\bin\Debug\netcoreapp3.1\IntroUI.exe
  15. Add-Type -Path C:\Temp\VSCodeIntro\IntroUI\bin\Debug\netcoreapp3.1\IntroLibrary.dll
  16. To add NUGet package cd into the Library folder and:
  17. dotnet add package xyz

Writing Portable Modules

  1. Check if dotnet psmodule is already installed dotnet new --list | Select-String psmodule
  2. Install the psmodule template dotnet new -i Microsoft.Powershell.Standard.module.Template
  3. New-Item -Name "PwshModule" -Path "C:\Temp" -ItemType Directory
  4. Set-Location "C:\Temp\PwshModule"
  5. dotnet new psmodule
  6. code -r .
  7. dotnet build
  8. Import-Module "C:\Temp\PwshModule\bin\Debug\netstandard2.0\PwshModule.dll"
  9. Get-Command -Module PwshModule
  10. Test-SampleCmdlet -?
  11. Test-SampleCmdlet -FavoriteNumber 7 -FavoritePet Cat