Search code examples
asp.netasp.net-core-2.0dotnet-clicakebuild

Exception thrown when running asp.net core application on Ubuntu


I have an Ubuntu VM which publishes an ASP.Net Core application 2.0 with CakeBuild .

The output is then moved to another Ubuntu VM where .Net Core SDK already installed.

When I try to dotnet the main dll file, the following exception is thrown:

Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Aborted (core dumped)

This is my build.cake

Task("Clean")
.Does(() =>
{
   CleanDirectory(binaryDir);
   CleanDirectory(objectDir);
   CleanDirectory(publishDir);
});

Task("Restore")
.IsDependentOn("Clean")
.Does(() =>
{
   DotNetCoreRestore(solutionPath);
});

Task("Build")
.IsDependentOn("Restore")
.Does(() => {
   var settings = new DotNetCorePublishSettings
   {
      Configuration = configuration, // Release
      OutputDirectory = publishDir,
      Runtime = runtime // linux-x64
   };

   DotNetCorePublish(solutionPath, settings);
});

In the application I am using two nuget packages which were published from a Windows machine (.Net Standard 2.0), will this cause dotnet to fail ? if yes, how to use nuget packages which are Linux compatible ?

Temp Solution

For now I am building the application using the native dotnet CLI publish command which is doing the trick; but that means for now cake build is useless for my case here (until the problem is fixed of course).


Solution

  • With further investigation, I found that providing the output or the runtime parameters as full names causes the issue (bug #8298), so I don't think it's a Cake issue, but rather they invoke the DotNetCorePublish command with full name arguments.

    cake/src/Cake.Common/Tools/DotNetCore/Publish/DotNetCorePublisher.cs lines 63-75

    // Output directory
    if (settings.OutputDirectory != null)
    {
        builder.Append("--output");
        builder.AppendQuoted(settings.OutputDirectory.MakeAbsolute(_environment).FullPath);
    }
    
    // Runtime
    if (!string.IsNullOrEmpty(settings.Runtime))
    {
        builder.Append("--runtime");
        builder.Append(settings.Runtime);
    }