Specifically on ubuntu, this doesn't appear to work.
For example, if I do this:
dotnet new sln -n HelloWorld
dotnet new classlib -n HelloLib
dotnet new console -n HelloApp
dotnet sln add ./HelloApp/HelloApp.csproj
dotnet sln add ./HelloLib/HelloLib.csproj
dotnet restore
dotnet build
cd HelloApp/
dotnet add reference ../HelloLib/HelloLib.csproj
And modify Program.cs to be:
using System;
using HelloLib;
namespace HelloApp
{
class Program
{
static void Main(string[] args)
{
var x = new Class1();
Console.WriteLine("Hello World!");
}
}
}
Then the application will compile, generating these artifacts:
HelloApp/bin$ du -a
4 ./Debug/netcoreapp1.1/HelloApp.deps.json
4 ./Debug/netcoreapp1.1/HelloApp.runtimeconfig.json
4 ./Debug/netcoreapp1.1/HelloApp.pdb
4 ./Debug/netcoreapp1.1/HelloLib.pdb
8 ./Debug/netcoreapp1.1/HelloApp.dll
4 ./Debug/netcoreapp1.1/HelloApp.runtimeconfig.dev.json
4 ./Debug/netcoreapp1.1/HelloLib.dll
36 ./Debug/netcoreapp1.1
40 ./Debug
44 .
...but executing the application fails:
$ dotnet HelloApp.dll
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'HelloLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
Aborted (core dumped)
If I remove the using HelloLib line, it works:
$ dotnet HelloApp.dll
Hello World!
What's up with that?
I presume its got something to do with the confusing incompatibility in the project files:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework> <-- **THIS**
</PropertyGroup>
</Project>
vs:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework> <-- **And THIS**
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\HelloLib\HelloLib.csproj">
<Project>{1607a379-5bae-423b-8efc-796a06556be0}</Project>
<Name>HelloLib</Name>
</ProjectReference>
</ItemGroup>
</Project>
I assumed this was just a bug.
...but other people seem to use .NET core without too much trouble.
So, am I doing something wrong?
Or are the people 'using' .NET core just not using class libraries, because they don't work?
(edit: versions:
Microsoft .NET Core Shared Framework Host
Version : 1.1.0
Build : 928f77c4bc3f49d892459992fb6e1d5542cb5e86
$ dpkg -l |grep dotnet
ii dotnet-dev-1.0.3 1.0.3-1 amd64 .NET Core SDK 1.0.3
$ cat /etc/issue
Ubuntu 16.10 \n \l