Eric
Eric

Reputation: 3211

.NET Core missing from Target framework list

Using Visual Studio 2017 Enterprise, I'm trying to change the target framework on a unit test project to .NET Core so that I can use xUnit. I don't see it in the list of available frameworks.

In my list of available frameworks, I see:

.NET Framework 2.0 -> 4.7.1 and several Unity Frameworks.  

This is despite the fact that I have .NET Core SDK 2.1.200 (x64), 2.1.202 (x64), and 2.1.500 (x64) installed.

Upvotes: 1

Views: 2057

Answers (2)

Panagiotis Kanavos
Panagiotis Kanavos

Reputation: 131180

Visual Studio only shows supported conversions. Converting from .NET Framework to .NET Core though isn't as simple as changing a version number.

You can use try-convert to make the necessary modifications to the project file. Make sure you use --diff-only first to inspect the changes.

You should check Nate McMaster's migration guide and Additions to the csproj format for .NET Core to understand the changes.

The tool isn't supported by Microsoft, nor is it guaranteed to perform a 100% conversion.

This tool is not supported in any way.

Who is this tool for?

This tool is for anyone looking to get a little help migrating their projects to .NET Core (or .NET SDK-style projects).

As the name suggests, this tool is not guaranteed to fully convert a project into a 100% working state. The tool is conservative and does as good of a job as it can to ensure that a converted project can still be loaded into Visual Studio and build. However, there are an enormous amount of factors that can result in a project that may not load or build that this tool explicitly does not cover. These include:

  • Complex, custom builds that you may have in your solution
  • API usage that is incompatible with .NET Core
  • Unsupported project types (such as Xamarin, WebForms, or WCF projects)

If the bulk of your codebase is generally capable of moving to .NET Core (such as lots of class libraries with no platform-specific code), then this tool should help quite a bit.

It is highly recommended that you use this tool on a project that is under source control.

Emphasis mine.

Why?

.NET Core and .NET Framework use very different csproj formats and handle package references differently, especially transient dependencies, ie packages that are needed by another package.

In .NET Framework packages.config contained all packages which means you had no idea which packages were really needed. In .NET Core there's no packages.config. The csproj files contains PackageReference elements only for the top-level dependencies.

In the old csproj format, you had to include every single source file explicitly. In the new format, all source files are included automatically, resulting in a file that's very easy to edit.

Making those changes isn't trivial. Until recently that was a manual process. Personally, I just removed everything, copied the minimal XML and added back package references until I got a succesful build. Even then, I had to manually add lines about included/excluded/copty-to-output files. If I had custom build steps with conditions etc, things would be a lot harder.

Upvotes: 0

Jimmy
Jimmy

Reputation: 28376

It seems like you have 2 options, both of which are easy:

Change your target framework to netcoreapp*

Edit your project file and change

<TargetFramework>net461</TargetFramework>

to

<TargetFramework>netcoreapp2.1</TargetFramework>

(or whichever version of .NET Core you wish to target. SDK 2.1.500 is netcoreapp2.1 I believe.)

Use XUnit in a .NET Framework project

Create a .NET Framework class library project and install the xunit NuGet package. Then you can just start using XUnit like normal, and it can reference your web project.

To run test in VS, you'll also need the xunit.runner.visualstudio package.

Upvotes: 1

Related Questions