Getting Started with C# and the Quantum Development Kit
C# is supported natively in the Quantum Development Kit making it easy to call Q# operations from C#.
To write C# programs, download and install the .NET Core SDK 2.1 or later from the .NET downloads page.
To download the latest templates for creating new C# projects and libraries that invoke Q# operations, execute this from a command line:
dotnet new -i Microsoft.Quantum.ProjectTemplates
To verify everything is correctly installed, create and run a new program using the following from a command line:
dotnet new console -lang Q# -o myApp cd MyApp dotnet run
If everything works ok, you will see a "Hello quantum world!" message, for example:
C:\>dotnet new console -lang Q# -o myApp The template "Console Application" was created successfully. C:\>cd myApp C:\Repos\myApp>dotnet run Hello quantum world!
Follow these instructions to migrate your .csproj files to the newest version:
- Consult Nuget.org for the
PackageReferencenumber, "0.n.xxxx.yyy" for the Microsoft Quantum Development Kit package.
- Projects need to be upgraded in order. If you have a solution with multiple projects, update each project in the order they are referenced.
- From a command line, run
dotnet cleanto remove all existing binaries and intermediate files.
- In a text editor, edit the .csproj file to change the version of all the "Microsoft.Quantum"
PackageReferenceto the package reference number, for example:
<PackageReference Include="Microsoft.Quantum.Standard" Version="0.n.xxxx.yyy" /> <PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.n.xxxx.yyy" />
- From the command line, run this command:
Take a look at the quickstart guide for information on how to write Q# operations and how to invoke them from C#.