0
$\begingroup$

I am trying to run a simple "Hello World" project in Q#, following this tutorial. I have completed the following steps (Step #s from tutorial link):

  • Step 1: Installed the latest version of Visual Studio 2019 (16.11.4 Preview 1.0)
  • Step 2: Installed Microsoft Quantum Development Kit
  • Step 3: Created a Q# Project using the Q# Application Template

The resulting Program.qs file appears in vs:

namespace Quantum.QSharpHelloWorld {

    open Microsoft.Quantum.Canon;
    open Microsoft.Quantum.Intrinsic;

    
    @EntryPoint()
    operation HelloQ () : Unit {
        Message("Hello quantum world!");
    }
}

The two namespaces I am trying to open show the red squiggly line, with the errors

QS6104: No namespace with the name "Microsoft.Quantum.Canon" exists.

QS6104: No namespace with the name "Microsoft.Quantum.Intrinsic" exists.

Additionally and likely the same root cause, the @EntryPoint annotation and Message() call fail:

QS6005: No type with the name "EntryPoint" exists in any of the open namespaces.

QS5022: No identifier with the name "Message" exists.

In the solution explorer for my projet QSharpHelloWorld, the Dependencies, Packages, and each of five packages (Microsoft.Quantum.CSharpGeneration, .EntryPointDriver, .QSharp.Core, .Runtime.Core, and .Standard) all have the yellow triangle warning indicating a problem.

The error is similar to the one in this question, except I'm not using Python so the accepted answer is irrelevant. I attempted to use the command suggested in another answer:

dotnet add QSharpHelloWorld.csproj package Microsoft.Quantum.CSharpGeneration

However, this failed with the following error, suggesting this is the wrong solution:

error: Error while performing Update for package 'Microsoft.Quantum.CSharpGeneration'. Cannot edit items in imported files -
error:   Item 'PackageReference' for 'Microsoft.Quantum.CSharpGeneration' in Imported file 'C:\[...]\.nuget\packages\microsoft.quantum.sdk\0.19.2109165653\Sdk\Sdk.props'.

I can't find any other obvious/easy menu options or fixes for this. Other questions I've found here on SE all seem to be related to Python integration, not using Visual Studio. I have the feeling I'm missing something trivial and obvious. Can anyone suggest additional steps I can take?

$\endgroup$
1
0
$\begingroup$

Thanks to @Maria Mykhailova who pointed me to this StackOverflow question with similar symptoms. This comment (lightly edited) in one of the answers was helpful:

Then there is something broken with your local NuGet cache. Empty it by removing everything inside the packages folder and then run the command dotnet restore again.

While I didn't "remove everything" I did remove the five problematic packages, which enabled the program to execute following a restore.

I still had the "red squiggly" symptom in the VS editor, but closing and reopening Visual Studio seemed to resolve these as well.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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