3

I use VS Code for C# and Unity3D and TypeScript and Angular and Python programming, so I have pretty much every required extension, including the .NET Framework and Core as well as the Quantum Development Kit (QDK) plus the Q# Interoperability Tools and also C# and Python extensions for VS Code.

I have devised the following steps to create my first quantum Hello World based on a few tutorials:

$ dotnet --version
$ dotnet --list-sdks
$ dotnet --list-runtimes

$ dotnet new globaljson                                     # Create a "global.json" file in your current directory folder.  
$ dotnet new globaljson --sdk-version 3.1.416 --force       # Change the current SDK version of your project.

$ dotnet new -i Microsoft.DotNet.Web.Spa.ProjectTemplates
$ dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.2-*"

# First, create a Q# application and a .NET host, and then make a call to Q# from the host.
# Create a project for your Q# library and for the .NET host that will call
# into the operations and functions defined in your Q# library.

$ dotnet new classlib -lang Q# -o quantum                         # Create a new Q# class-library project.
$ dotnet new console -lang C# -o host                             # Create a new C# console project.

$ cd host                                                         # Navigate into the C# host directory.
$ dotnet add reference ../quantum/quantum.csproj                  # Add your Q# class-library project as a reference to your C# console project.

$ cd ..                                                           # Exit the C# host directory.
$ dotnet new sln -n quantum-dotnet                                # Create a new solution for both projects.
$ dotnet sln quantum-dotnet.sln add ./quantum/quantum.csproj      # Add the Q# class-library project to the solution.
$ dotnet sln quantum-dotnet.sln add ./host/host.csproj            # Add the C# host project to the solution.

# The -o or --output command specifies the location to place the generated output.

However, as soon as this is all done, I get the following load of errors:

enter image description here

What am I doing wrong? What am I missing?


Here is some additional info:

$ dotnet --list-sdks
3.1.416 [C:\Program Files\dotnet\sdk]
5.0.404 [C:\Program Files\dotnet\sdk]

$ dotnet --version  
3.1.416

$ dotnet restore
  Determining projects to restore...
  Restored C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj (in 484 ms).
  Restored C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\host\host.csproj (in 782 ms).

When I run dotnet build, I get the following:

Microsoft (R) Build Engine version 16.7.2+b60ddb6f4 for .NET Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... All projects are up-to-date for restore. It was not possible to find any compatible framework version The framework 'Microsoft.NETCore.App', version '2.0.0' was not found. - The following frameworks were found: 3.1.22 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 5.0.13 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at: - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.0.0&arch=x64&rid=win10-x64 C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\build\Microsoft.Quantum.Development.Kit.targets(17,5): error MSB3073: The command "dotnet C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\build../tools/qsc/qsc.dll --input "Operation.qs" --references "C:\Users\Muhy.nuget\packages\microsoft.quantum.canon\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Canon.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.MetaData.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Primitives.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Common.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Core.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Simulators.dll" --outputpath obj\qsharp\src" exited with code -2147450730. [C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj]

Build FAILED.

C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\build\Microsoft.Quantum.Development.Kit.targets(17,5): error MSB3073: The command "dotnet C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\build../tools/qsc/qsc.dll --input "Operation.qs" --references "C:\Users\Muhy.nuget\packages\microsoft.quantum.canon\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Canon.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.MetaData.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Primitives.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Common.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Core.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit\0.2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Simulators.dll" --outputpath obj\qsharp\src" exited with code -2147450730. [C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj] 0 Warning(s) 1 Error(s)


When I also build the project (dotnet build quantum-dotnet.sln and dotnet build ./host/host.csproj) I get the same errors.

Muhy
  • 630
  • 1
  • 6
  • 12
  • 1
    Could you post the output of `dotnet --list-sdks` and `dotnet restore` – Sarmad Georgie Feb 19 '22 at 11:39
  • @Sarmad Georgie I added this info to the bottom of my post. Thanks for trying to help. – Muhy Feb 21 '22 at 08:48
  • 1
    Looks ordinary, try removing `bin` and `obj` folders and building again, if you could also post the content of the `.csproj` file that may help. – Sarmad Georgie Feb 21 '22 at 10:03
  • @SarmadGeorgie I did that. Still the exact same errors. Please see my edited post; I added the outputs of the builds. Thanks – Muhy Feb 26 '22 at 08:32

1 Answers1

3

With help from a user on another forum, it turns out the problem was the command:

dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.2-*"

which installed version 0.2.1802.1603-preview which is quite old. The latest version is 0.22.187631.

This did the trick:

dotnet new -i "Microsoft.Quantum.ProjectTemplates"

Followed by:

dotnet new --update-apply

to update all the project templates. After this, re-creating the projects fixed all the errors.

Now, I believe the following set of instructions should work for every beginner:

# Install the .NET Framework and Core as well as the Quantum Development Kit (QDK)
# plus the Q# Interoperability Tools and also C# and Python extensions for VS Code.

$ dotnet --version
$ dotnet --list-sdks
$ dotnet --list-runtimes

$ dotnet new globaljson                                             # Create a "global.json" file in your current directory folder.  
$ dotnet new globaljson --sdk-version 3.1.416 --force               # Change the current SDK version of your project to .NET 3.1.416

$ dotnet new -i Microsoft.DotNet.Web.Spa.ProjectTemplates
$ dotnet new -i "Microsoft.Quantum.ProjectTemplates"
$ dotnet new --update-apply

# First, create a Q# application and a .NET host, and then make a call to Q# from the host.
# Create a project for your Q# library and for the .NET host that will call
# into the operations and functions defined in your Q# library.

$ dotnet new classlib -lang Q# -o quantum                           # Create a new Q# class-library project.
$ dotnet new console -lang C# -o host                               # Create a new C# console project.
                                                                    # The -o or --output command specifies the location to place the generated output.

$ cd host                                                           # Navigate into the C# host directory.
$ dotnet add reference ../quantum/quantum.csproj                    # Add your Q# class-library project as a reference to your C# console project.

$ cd ..                                                             # Exit the C# host directory.
$ dotnet new sln -n quantum-dotnet                                  # Create a new solution for both projects.
$ dotnet sln quantum-dotnet.sln add ./quantum/quantum.csproj        # Add the Q# class-library project to the solution.
$ dotnet sln quantum-dotnet.sln add ./host/host.csproj              # Add the C# host project to the solution.

$ cd host
$ dotnet build
$ dotnet run
Muhy
  • 630
  • 1
  • 6
  • 12