Back to blog

Part of the series: A Scripters Next Steps

A series introducing C# to experienced PowerShell developers

C# PowerShell Module - Hello World

Getting started with your first C# PowerShell module

dotnet new classlib -o ./ASNS.Intro -f net8.0

Run the following command to add the PowerShell SDK to the project

dotnet add package Microsoft.PowerShell.SDK -v 7.5.4

Your csproj should now look like this

<Project Sdk="Microsoft.NET.Sdk">  
  
  <PropertyGroup>  
    <TargetFramework>net8.0</TargetFramework>  
    <ImplicitUsings>enable</ImplicitUsings>  
    <Nullable>enable</Nullable>  
  </PropertyGroup>  
  
  <ItemGroup>  
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4" />  
  </ItemGroup>  
  
</Project>

just for good measure, go ahead and run dotnet build to make sure everything works as expected

you should see output like the following

 dotnet build
Restore complete (0.3s)
  ASNS.Intro net8.0 succeeded (1.7s) → bin/Debug/net8.0/ASNS.Intro.dll

Build succeeded in 2.3s

Excellent! you have a powershell module! Ok, not quite, but you do have a C# Class library, it just doesn’t expose anything yet, or include anything for that matter

Next ->