Reputation: 2004
I'm having a nightmare building a .NET Core console project on OS X.
I'm using .NET version 1.0.1.
When I try running the following command from my terminal
dotnet publish --framework netcoreapp1.1 --runtime osx.10.11-x64
I get the following error:
\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v1.1/osx.10.11-x64
I have googled this and all the documentation mentions adding runtimes to project.json, like this.
"runtimes": {
"win10-x64": {},
"win8-x64": {},
"osx.10.10-x64": {},
"osx.10.11-x64": {
"#import": [ "osx.10.11", "osx.10.10-x64" ]
},
"osx.10.12-x64": {
"#import": [ "osx.10.12", "osx.10.11-x64" ]
},
"debian.8-x64": {}
},
But I don't have a projects.json, only a projects.assets.json which is where the compiler seems to be looking.
After further investigation, I found the following link. It eems that file project.json is no longer used!
A mapping between project.json and csproj properties
Which seems insane to me??!??!
Anyway, it suggests adding the runtimes to the .csproj file.
Which I have done:
PropertyGroup>
<RuntimeIdentifiers>win7-x64;osx.10-11-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
</PropertyGroup>
And I still get the same error.
So I have a few questions.
Why is the compiler looking in projects.assets.json? I've tried adding the runtimes to this file, but still it doesn't see it. Why?
Why is the compiler not looking in projects.json or the .csproj file where everyone else on the web seems to say it should be looking?
How can I change where the compiler looks?
It feels like I'm missing something simple.
BTW: If I just run the project from my console using dotnet {projectname} it runs just fine (on my Mac) so there aren't any problems with the build, etc.
Update ---
I got this a bit further. It seems I needed to have this in my project.assets.json* file:
"runtimes": {
"osx.10-11-x64": {
"#import": []
},
"ubuntu.16.04-x64": {
"#import": []
},
"win7-x64": {
"#import": []
}
}
Notice the OS X runtime is osx.10-11-x64, not osx.10.11-x64. This typo seems to be everywhere on the web. Maybe it has changed.
So it now compiles and I get a publish folder.
However, trying to run this now gives the following error
A fatal error was encountered. The library 'libhostpolicy.dylib' required to execute the application was not found in 'xxx/xxx'.
I have googled this and none of the suggestions or reasons seem to match my situation. I have done a dotnet restore
, a build and publish for the correct runtime, etc. Also my deployment type is not 'Platform' which seems to be another reason for this error.
Update 2!!!! I got it working - almost!!
It turns out for some reason the runtimeconfig.json file was empty.
I needed to add this:
{
"runtimeOptions": {
"framework": {
"name": "Microsoft.NETCore.App",
"version": "1.1.0"
}
}
}
So - next trick is to find out why this is not being done automatically by the compiler!!
Upvotes: 4
Views: 6489
Reputation: 100581
TL;DR this works fine:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeIdentifiers>win7-x64;osx.10.11-x64;ubuntu.16.04-x64</RuntimeIdentifiers>
</PropertyGroup>
</Project>
published through:
testapp$ dotnet restore
testapp$ dotnet publish -r osx.10.11-x64
testapp$ ./bin/Debug/netcoreapp1.1/osx.10.11-x64/publish/testapp
Hello World!
In order to publish self-contained you need three things:
project.assets.json
file. This is done through either:
RuntimeIdentifier
(singular) property in the project file. This will pin/fix the project to one runtime which then is always used for build & publish as well.RuntimeIdentifiers
(plural) property in the project file specifying multiple RIDs but doesn't require every build / publish to be runtime-specific, allowing you to specify the one you want on publish through the -r
argument.dotnet restore -r osx.10.11-x64
.2.A RuntimeIdentifier that has been restored for must be specified during publish, either by using dotnet publish -r osx.10.11-x64
or by specifying RuntimeIdentifier
(singular) in the project file
<OutputType>Exe</OutputType>
in the project fileUpvotes: 4