Update the Quantum Development Kit (QDK) to the latest version
Learn how to update the Quantum Development Kit (QDK) to the latest version.
This article assumes that you already have the QDK installed. If you are installing for the first time, then please refer to the installation guide.
We recommend keeping up to date with the latest QDK release. Follow this update guide to upgrade to the most recent QDK version. The process consists of two parts:
- Updating your existing Q# files and projects to align your code with any updated syntax.
- Updating the QDK itself for your chosen development environment.
Update Q# projects
Regardless of whether you are using C# or Python to host Q# operations, follow these instructions to update your Q# projects.
First, check that you have the latest version of the .NET SDK 6.0. Run the following command in the command prompt:
dotnet --versionVerify the output is
6.0.100or higher. If not, install the latest version and check again. Then follow the instructions below depending on your setup (Visual Studio, Visual Studio Code, or directly from the command prompt).
Update Q# projects in Visual Studio
Update to the latest version of Visual Studio 2022, see here for instructions.
Open your solution in Visual Studio.
From the menu, select Build -> Clean Solution.
In each of your .csproj files, update the target framework to
net6.0(ornetstandard2.1if it is a library project). That is, edit lines of the form:<TargetFramework>net6.0</TargetFramework>You can find more details on specifying target frameworks here.
In each of the .csproj files, set the SDK to
Microsoft.Quantum.Sdk, as indicated in the line below. Please notice that the version number should be the latest available, and you can determine it by reviewing the release notes.<Project Sdk="Microsoft.Quantum.Sdk/0.24.201332">Save and close all files in your solution.
Select Tools -> Command Line -> Developer Command Prompt. Alternatively, you can use the package management console in Visual Studio.
For each project in the solution, run the following command to remove this package:
dotnet remove [project_name].csproj package Microsoft.Quantum.Development.KitIf your projects use any other Microsoft.Quantum or Microsoft.Azure.Quantum packages (for example, Microsoft.Quantum.Numerics), run the
addcommand for these to update the version used.dotnet add [project_name].csproj package [package_name]Close the command prompt and select Build -> Build Solution (do not select Rebuild Solution).
You can now skip ahead to update your Visual Studio QDK extension.
Update Q# projects in Visual Studio Code
- In Visual Studio Code, open the folder containing the project to update.
- Select Terminal -> New Terminal.
- Follow the instructions for updating using the command prompt (directly below).
Update Q# projects using the command prompt
Navigate to the folder containing your main project file.
Run the following command:
dotnet clean [project_name].csprojDetermine the current version of the QDK. To find it, you can review the release notes. The version will be in a format similar to
0.24.201332.In each of your
.csprojfiles, go through the following steps:Update the target framework to
net6.0(ornetstandard2.1if it is a library project). That is, edit lines of the form:<TargetFramework>net6.0</TargetFramework>You can find more details on specifying target frameworks here.
Replace the reference to the SDK in the project definition. Make sure that the version number corresponds to the value determined in step 3.
<Project Sdk="Microsoft.Quantum.Sdk/0.24.201332">Remove the reference to package
Microsoft.Quantum.Development.Kitif present, which will be specified in the following entry:<PackageReference Include="Microsoft.Quantum.Development.Kit" Version="0.24.201332" />Update the version of the all the Microsoft Quantum packages to the most recently released version of the QDK (determined in step 3). Those packages are named with the following patterns:
Microsoft.Quantum.* Microsoft.Azure.Quantum.*References to packages have the following format:
<PackageReference Include="Microsoft.Quantum.Compiler" Version="0.24.201332" />Save the updated file.
Restore the dependencies of the project, by doing the following:
dotnet restore [project_name].csproj
Note
For versions
0.24.201332and above, the target framework was upgraded fromnetcoreapp3.1tonet6.0(except for libraries). If using an older QDK, you should keep this value as is.Navigate back to the folder containing your main project and run:
dotnet build [project_name].csproj
With your Q# projects now updated, follow the instructions below to update the QDK itself.
Update the QDK
The process to update the QDK varies depending on your development language and environment. Select your development environment below.
- Python: update the
qsharppackage - Jupyter Notebooks: update the IQ# kernel
- Visual Studio: update the QDK extension
- VS Code: update the QDK extension
- Command line and C#: update project templates
- Python: Update the azure-quantum Python package
Update the qsharp Python package
The update procedure depends on whether you originally installed using conda or using the .NET CLI and pip.
Activate the conda environment where you installed the
qsharppackage, and then run this command to update it:conda update -c microsoft qsharpRun the following command from the location of your
.qsfiles:python -c "import qsharp; qsharp.reload()"
You can now use the updated qsharp Python package to run your existing quantum programs.
Update the IQ# Jupyter kernel
The update procedure depends on whether you originally installed using conda or using the .NET CLI and pip.
Activate the conda environment where you installed the
qsharppackage, and then run this command to update it:conda update -c microsoft qsharpRun the following command from a cell in each of your existing Q# Jupyter Notebooks:
%workspace reload
You can now use the updated IQ# kernel to run your existing Q# Jupyter Notebooks.
Update the Visual Studio QDK extension
Update the Q# Visual Studio extension
- Visual Studio prompts you to accept updates to the Quantum Visual Studio extension
- Accept the update
Note
The project templates are updated with the extension. The updated templates apply to newly created projects only. The code for your existing projects is not updated when the extension is updated.
Update the VS Code QDK extension
Update the Quantum VS Code extension
- Restart VS Code
- Navigate to the Extensions tab
- Select the Microsoft Quantum Development Kit for Visual Studio Code extension
- Reload the extension
C# using the dotnet command-line tool
Update the Quantum project templates for .NET
From the command prompt:
dotnet new -i Microsoft.Quantum.ProjectTemplatesAlternatively, if you intend to use the command-line templates, and already have the VS Code QDK extension installed, you can update the project templates from the extension itself:
- Update the QDK extension
- In VS Code, go to View -> Command Palette
- Select Q#: Install command line project templates
- After a few seconds you should get a popup confirming "project templates installed successfully"
Update the azure-quantum Python package
Update to the latest
azure-quantumPython package by using the Python Package Installer (PIP)pip install --upgrade azure-quantumIf you encounter any issues please ensure that Python and PIP are up to date. For information on the latest version requirements, please follow our guide for installing and using the azure-quantum Python package
Maklum balas
Kirim dan lihat maklum balas untuk