5

I created an ASP.NET Core Web Application in VS 2015. The Add unit tests checkbox was available for the ASP.NET 4.x templates, but when I selected ASP.NET 5 templates it was grayed out. I tried creating the project anyway with plans to add my own unit tests.

I added another project to the solution but I'm not able to link the two. When I right-click the references of the UnitTest project and hit Add Reference, I can see the original project as an option.

But when I check the box and hit OK, I get a dialog box that says, "A reference to 'PangolinWeb' could not be added. An assembly must have a 'dll' or 'exe' extension in order to be referenced."

Why can't I add an ASP.NET Core project as a reference? Is this the only way to make all of its classes and methods available to my UnitTest project?

2
  • I am working with ASP.NET Core now for 1 year. In my current project my team is using xUnit, which I think is a better choice for ASP.NET Core. For more details about it, check xunit.github.io Commented May 3, 2016 at 19:35
  • Check out this answer. Commented May 4, 2016 at 14:02

2 Answers 2

13

The project still compiles to a dll that you can reference, so instead of referencing the project, reference the dll in the bin folder of the Core project

  1. Add a reference to the file using the Add Reference, browse dialog

  2. Edit the csproj to use a variable for the configuration so it builds in release mode correctly. e.g.

`

<Reference Include="YourLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\YourLibrary\bin\$(Configuration)\net45\YourLibrary.dll</HintPath>
  </Reference>
  1. use the solution project build order to make the referencing project build after the dotnetcore library project.
Sign up to request clarification or add additional context in comments.

2 Comments

Wow... so simple. Good call :)
i like this answer.
3

You cannot add a ASP.NET 5 (ASP.NET Core) project as a reference to a .NET Framework .csproj project (which I presume your unit test project is). This is a feature gap in the current Visual Studio tooling but will be fixed (IMHO as part of the upcoming RC2). Why? Because it is not implemented ;).

I also want to highlight that the answer of Juliano is right. xUnit is the framework of choice, by the .NET and ASP.NET teams.

Solution ideas: Include the classes as a linked file into your csproj. Like that you can compile it twice and test it once. Not the finest solution but a workaround for a while till the tooling will catch up.

2 Comments

Does anybody have an update on the timeline for when this will be fixed?
The project was delayed, since they decided to scrap the project.json. They switch to csproj and mscorlib shim support with .NET Core 1.2. ETA Summer 2017

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.