4
$\begingroup$

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.

$\endgroup$
2
  • 1
    $\begingroup$ I don't see anything wrong with this setup. What happens when you try to build your solution or the host project? i.e.: dotnet build quantum-dotnet.sln or dotnet build ./host/host.csproj? $\endgroup$
    – El capi
    Feb 21, 2022 at 21:09
  • $\begingroup$ @Elcapi Thanks for your reply. I have added the output of the builds that you ask about. Please see my edited post. $\endgroup$
    – Muhy
    Feb 26, 2022 at 8:27

1 Answer 1

2
$\begingroup$

I see the problem now. The command:

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

installed version 0.2.1802.1603-preview, which is many years old. Our latest version is 0.22.187631.

Is there any specific reason you decided to specify a version number when installing the templates package? This should work:

dotnet new -i "Microsoft.Quantum.ProjectTemplates"

My recommendation is to run:

dotnet new --update-apply

to update all your project templates. After this, re-create the projects. Let us know if this works.

$\endgroup$
1
  • $\begingroup$ Bless you! It fixed all the errors. It now works like a charm. Much appreciated :-) $\endgroup$
    – Muhy
    Feb 27, 2022 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.