运行 asp.net 核心应用程序在 Ubuntu 上抛出异常
Exception thrown when running asp.net core application on Ubuntu
我有一个 Ubuntu 虚拟机,其中 publishes
一个带有 CakeBuild 的 ASP.Net 核心应用程序 2.0。
然后将输出移动到另一个已安装 .Net Core SDK 的 Ubuntu VM。
当我尝试 dotnet
主 dll 文件时,抛出以下异常:
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)
这是我的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);
});
在应用程序中,我使用了两个从 Windows 机器(.Net Standard 2.0)发布的 nuget 包,这会导致 dotnet
失败吗?如果是,如何使用 Linux 兼容的 nuget 包?
临时解决方案
目前,我正在使用本机 dotnet CLI publish
命令构建应用程序,该命令正在执行此操作;但这意味着现在 cake build 对我这里的情况毫无用处(当然,直到问题得到解决)。
通过进一步调查,我发现提供 output
或 runtime
参数作为全名会导致问题 (bug #8298),所以我认为这不是蛋糕问题,而是他们使用全名参数调用 DotNetCorePublish
命令。
cake/src/Cake.Common/Tools/DotNetCore/Publish/DotNetCorePublisher.cs 第 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);
}
我有一个 Ubuntu 虚拟机,其中 publishes
一个带有 CakeBuild 的 ASP.Net 核心应用程序 2.0。
然后将输出移动到另一个已安装 .Net Core SDK 的 Ubuntu VM。
当我尝试 dotnet
主 dll 文件时,抛出以下异常:
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)
这是我的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);
});
在应用程序中,我使用了两个从 Windows 机器(.Net Standard 2.0)发布的 nuget 包,这会导致 dotnet
失败吗?如果是,如何使用 Linux 兼容的 nuget 包?
临时解决方案
目前,我正在使用本机 dotnet CLI publish
命令构建应用程序,该命令正在执行此操作;但这意味着现在 cake build 对我这里的情况毫无用处(当然,直到问题得到解决)。
通过进一步调查,我发现提供 output
或 runtime
参数作为全名会导致问题 (bug #8298),所以我认为这不是蛋糕问题,而是他们使用全名参数调用 DotNetCorePublish
命令。
cake/src/Cake.Common/Tools/DotNetCore/Publish/DotNetCorePublisher.cs 第 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);
}