缺少类型、命名空间、指令和程序集引用
Missing types, namespaces, directives, and assembly references
我将 VS Code
用于 C#
和 Unity3D
以及 TypeScript
和 Angular
以及 Python
编程,所以我几乎每个需要扩展,包括 .NET Framework
和 Core
以及 Quantum Development Kit (QDK)
加上 Q# Interoperability Tools
以及 C#
和 Python
扩展 VS Code
.
根据一些教程,我设计了以下步骤来创建我的第一个量子 Hello World:
$ 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.
但是,一旦完成这一切,我就会收到以下错误负载:
我做错了什么?我错过了什么?
这里有一些额外的信息:
$ 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).
当我 运行 dotnet build
时,我得到以下信息:
Microsoft (R) 构建引擎版本 16.7.2+b60ddb6f4 for .NET
版权所有 (C) Microsoft Corporation。保留所有权利。
正在确定要恢复的项目...
所有项目都是最新的以进行恢复。
无法找到任何兼容的框架版本
未找到框架 'Microsoft.NETCore.App',版本“2.0.0”。
- 发现以下框架:
3.1.22 在 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
5.0.13 在 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
您可以通过安装指定框架and/or SDK解决问题。
可以在以下位置找到指定的框架:
- 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[=71=].2.1802.1603-preview\build\Microsoft.Quantum.Development.Kit.targets(17,5): 错误 MSB3073: 命令"dotnet C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\build../tools/qsc/qsc.dll --input "Operation.qs" --references "C:\Users\Muhy.nuget\packages\microsoft.quantum.canon[=79=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Canon.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.MetaData.dll" "C: \Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Primitives.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Common.dll" "C:\Users\Muhy. nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Core.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll" "C:\Users\Muhy.nuget\packages\microsoft. quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Simulators.dll" --outputpath obj\qsharp\src" 退出代码 -2147450730。 [C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj]
构建失败。
C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\build\Microsoft.Quantum.Development.Kit.targets(17,5):错误 MSB3073:命令“dotnet C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\build../tools/qsc/qsc.dll - -input "Operation.qs" --references "C:\Users\Muhy.nuget\packages\microsoft.quantum.canon[=79=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Canon.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.MetaData.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Primitives.dll" " C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Common.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Core.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Simulators.dll" --outputpath obj\qsharp\src" 退出代码 - 2147450730。 [C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj]
0 条警告
1 个错误
当我也构建项目(dotnet build quantum-dotnet.sln
和 dotnet build ./host/host.csproj
)时,我得到了同样的错误。
在另一个论坛用户的帮助下,发现问题出在命令上:
dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.2-*"
哪个安装的版本0.2.1802.1603-preview
太旧了。最新版本是 0.22.187631
.
这成功了:
dotnet new -i "Microsoft.Quantum.ProjectTemplates"
其次是:
dotnet new --update-apply
更新所有项目模板。此后,re-creating 项目修复了所有错误。
现在,我相信以下一组说明应该适用于每个初学者:
# 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
我将 VS Code
用于 C#
和 Unity3D
以及 TypeScript
和 Angular
以及 Python
编程,所以我几乎每个需要扩展,包括 .NET Framework
和 Core
以及 Quantum Development Kit (QDK)
加上 Q# Interoperability Tools
以及 C#
和 Python
扩展 VS Code
.
根据一些教程,我设计了以下步骤来创建我的第一个量子 Hello World:
$ 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.
但是,一旦完成这一切,我就会收到以下错误负载:
我做错了什么?我错过了什么?
这里有一些额外的信息:
$ 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).
当我 运行 dotnet build
时,我得到以下信息:
Microsoft (R) 构建引擎版本 16.7.2+b60ddb6f4 for .NET 版权所有 (C) Microsoft Corporation。保留所有权利。
正在确定要恢复的项目... 所有项目都是最新的以进行恢复。 无法找到任何兼容的框架版本 未找到框架 'Microsoft.NETCore.App',版本“2.0.0”。 - 发现以下框架: 3.1.22 在 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] 5.0.13 在 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
您可以通过安装指定框架and/or SDK解决问题。
可以在以下位置找到指定的框架: - 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[=71=].2.1802.1603-preview\build\Microsoft.Quantum.Development.Kit.targets(17,5): 错误 MSB3073: 命令"dotnet C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\build../tools/qsc/qsc.dll --input "Operation.qs" --references "C:\Users\Muhy.nuget\packages\microsoft.quantum.canon[=79=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Canon.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.MetaData.dll" "C: \Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Primitives.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Common.dll" "C:\Users\Muhy. nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Core.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll" "C:\Users\Muhy.nuget\packages\microsoft. quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Simulators.dll" --outputpath obj\qsharp\src" 退出代码 -2147450730。 [C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj]
构建失败。
C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\build\Microsoft.Quantum.Development.Kit.targets(17,5):错误 MSB3073:命令“dotnet C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\build../tools/qsc/qsc.dll - -input "Operation.qs" --references "C:\Users\Muhy.nuget\packages\microsoft.quantum.canon[=79=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Canon.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.MetaData.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Primitives.dll" " C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Common.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Core.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.dll" "C:\Users\Muhy.nuget\packages\microsoft.quantum.development.kit[=71=].2.1802.1603-preview\lib\netstandard2.0\Microsoft.Quantum.Simulation.Simulators.dll" --outputpath obj\qsharp\src" 退出代码 - 2147450730。 [C:\Users\Muhy\Dropbox\Q\Q#-programs\Qtest\quantum\quantum.csproj] 0 条警告 1 个错误
当我也构建项目(dotnet build quantum-dotnet.sln
和 dotnet build ./host/host.csproj
)时,我得到了同样的错误。
在另一个论坛用户的帮助下,发现问题出在命令上:
dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.2-*"
哪个安装的版本0.2.1802.1603-preview
太旧了。最新版本是 0.22.187631
.
这成功了:
dotnet new -i "Microsoft.Quantum.ProjectTemplates"
其次是:
dotnet new --update-apply
更新所有项目模板。此后,re-creating 项目修复了所有错误。
现在,我相信以下一组说明应该适用于每个初学者:
# 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