Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling .NET Core VS17

For the last couple of days, I've been trying to compile my .NET Core console application, and upload it to a VPS running "Windows Server 2012 R2". The reason I am using .NET Core is because this is needed for the library - Discord.Net 1.0.

The first thing I tried was simply taking my release DLL file and data, with the following file structure:

LeveledStudios.deps
LeveledStudios.dll
LeveledStudios.pdb
LeveledStudios.runtimeconfig.dev
LeveledStdios.runtimeconfig

This worked fine for execution on the PC I developed it on, however I then went into my server, ran "dotnet LeveledStudios.dll", and was faced with the error

Error: assembly specified in the dependencies manifest was not found -- package: 'discord.net.commands', version '1.0.0-rc-00546', path: 'lib/netstandard1.3/Discord.Net.Commands.dll`

Noticing this fitted the structure of the .nuget folder on my development PC. I copied it across and faced the same issue, and tried to copy it into the same folder as leveledstudios.dll, only to run into some .dll's which refused to work. This also included missing system DLL files, like System.Net.Http, etc.

I did some googling, and saw information about self contained .NET Core applications. This sounds perfect because clearly my problem was that it was not compiling with all my additional libraries. I was a little confused because I did not have a project.json file, as mentioned in all the documentation I read on it.

However when running:

dotnet restore
dotnet build -r win10-x64

I get a host of errors, suggesting none of the system libraries are compiled:

Errors

The contents of LeveledStudios.csproj:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Discord.Net" Version="1.0.0-rc-00546" />
    <PackageReference Include="Discord.Net.Commands" Version="1.0.0-rc-00546" />
    <PackageReference Include="Discord.Net.Core" Version="1.0.0-rc-00546" />
    <PackageReference Include="Discord.Net.WebSocket" Version="1.0.0-rc-00546" />
    <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.2-beta2" />
  </ItemGroup>
</Project>

How can I fix this?

like image 444
OllysCoding Avatar asked Nov 08 '22 03:11

OllysCoding


1 Answers

...self contained .NET Core applications [sound] perfect... however... I get a host of errors, suggesting none of the system libraries are compiled.

To resolve the errors that happened when you built as a self-contained application, add this one line to your *.csproj file:

<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>

Restore will then bring down the runtime, allowing you to build and publish as a self-contained application.

dotnet restore
dotnet build -r win10-x64
dotnet publish -c release -r win10-x64

The final *.csproj file looks like this:

<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
  <PropertyGroup>
    <OutputType>exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Discord.Net" Version="1.0.0-rc-00546" />
    <PackageReference Include="Discord.Net.Commands" Version="1.0.0-rc-00546" />
    <PackageReference Include="Discord.Net.Core" Version="1.0.0-rc-00546" />
    <PackageReference Include="Discord.Net.WebSocket" Version="1.0.0-rc-00546" />
    <PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="9.0.2-beta2" />
  </ItemGroup>
</Project>

That's how to publish as a self-contained application, which is one alternative to resolve your initial problem.

The other alternative (which Ryan suggested and which you said did not work) is to use a framework-dependent application, in which case you do not need the RuntimeIdentifiers property. You can then run the same commands but without specifying the runtime.

dotnet restore
dotnet build
dotnet publish

The publish files, which will include the Discord dependencies, will be here:

bin\Debug\netcoreapp1.0\publish
like image 168
Shaun Luttin Avatar answered Nov 15 '22 07:11

Shaun Luttin