Why is Visual Studio telling me that netstandard2.1 is incompatible with netcoreapp2.1?
This information seems to be wrong. The page .NET Standard versions says that .NET Standard 2.1 is supported since .NET Core 3.0
Missing types, namespaces, directives, and assembly references
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
Use .NET Core with legacy .NET framework dlls
Difficult topic. Generally .NET Framework and .NET Core are incompatible. They target a different set of assemblies (mscorlib vs. System.Runtime) which causes incompatibilities since all usages of types are prefixed with the assembly the type is from.
Starting with .NET Core 2 (currently in preview), you can reference .NET Framework assemblies through an invisible compatibility shim. This allows you to reference the assembly and compile successfully.
It doesn't guarantee though that the application will run successfully, since .NET Core doesn't provide all the APIs from .NET Framework. You'll get PlatformNotSupportedException
or MissingTypeException
and friends at runtime if that's the case.
The current .NET SDK does not support targeting .NET Standard 2.0 error in Visual Studio 2017 update 15.3
It sounds like installing the VS2017 update for that specific version didn't also install the .NET Core 2.0 SDK. You can download that here.
To check which version of the SDK you've already got installed, run
dotnet --info
from the command line. Note that if there's a global.json
file in either your current working directory or any ancestor directory, that will override which version of the SDK is run. (That's useful if you want to enforce a particular version for a project, for example.)
Judging by comments, some versions of VS2017 updates do install the .NET Core SDK. I suspect it may vary somewhat over time.
Related Topics
How to Compare Two Objects in Unit Test
When Should I Use Out Parameters
Entity Framework the Underlying Provider Failed on Open
How to Write Out a Text File in C# with a Code Page Other Than Utf-8
Internal Server Error While Running a Simple .Net Core MVC Application on Ubuntu 16.04
How to Detect Iis Version Using C#
Using a Wwwroot Folder (ASP.NET Core Style) in ASP.NET 4.5 Project
C# - Elegant Way of Partitioning a List
Windows Phone 8: Media File Access
Filesystemwatcher to Watch Unc Path
Twoway-Bind View's Dependencyproperty to Viewmodel's Property
How to Prevent Xss (Cross Site Scripting) Whilst Allowing HTML Input
Using Ienumerable Without Foreach Loop
How to Make the .Net Httpclient Use Http 2.0
Getting @@Identity from Tableadapter
Monodevelop + Naudio + Ubuntu Linux Tells Me Winmm.Dll Not Found
How to Save Dlls in a Different Folder When Compiling in Visual Studio
How Does Java's Use-Site Variance Compare to C#'s Declaration Site Variance