I am creating a .Net Core Library
that can be consumed by ASP.NET Core
Application. By default Visual Studio create project.json as below
{
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"version": "1.0.0-*"
}
I think its recommended to use netstandard1.x
for libraries that will be consumed by other applications. I am going to remove "imports": "dnxcore50"
because that was for older .NET Core preview versions (Before .NET Core 1.0 RTM and .NET Core RC2 were released)
Now I wanted to unit test this library using xunit
so followed the article Getting started with xUnit.net (.NET Core / ASP.NET Core)
However xunit suggest to mark the library as .Net Core Application
You may have noticed that part of what we did here was mark your class library as a .NET Core Application (the netcoreapp1.0 framework). When using .NET CLI for testing, unit test projects are actually an application*, not a class library. If you forget to make this change, the compiler will tell you that dotnet-test-xunit is not compatible with your class library project. We tell Visual Studio to generate a class library, though, because it most closely matches our desired project structure.
- The application's Main function is provided by the xUnit.net runner, not by you.
So I have updated the project.josn as suggested and I was able to run the unit test. However I have questions:
1> Is it recommended to change the target framework of the .Net Core library from netstandard1.6
to netcoreapp1.0
when that library can be consumed by other applications?