我正在开发一个.NET Core项目。我的项目在.NET核心1.1上工作正常,因为我可以发布Windows,Mac和Ubuntu的版本,它们按预期运行。
但是,我想转移到.NET Core 2.0以利用新功能,并减少我必须执行的构建数量,如https://stackoverflow.com/a/45705268/8363669
中所述我的项目包括一个使用.NET Core 2.0的独立ASP.NET Core应用程序和一个使用NET Standard 2.0的库
应用程序引用包,如下所示:
"Microsoft.ApplicationInsights.AspNetCore" Version="2.1.1" />
"Microsoft.AspNetCore" Version="2.0.0"
"Microsoft.AspNetCore.Mvc" Version="2.0.0"
"Microsoft.AspNetCore.StaticFiles" Version="2.0.0"
"Microsoft.EntityFrameworkCore.Design" Version="2.0.0"
"Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0"
"Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.3"
"Microsoft.Extensions.Logging.Debug" Version="2.0.0"
"Microsoft.NETCore.Runtime.CoreCLR" Version="2.0.0"
"Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0"
"Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0"
"NETStandard.Library" Version="2.0.0" />
"Newtonsoft.Json" Version="10.0.3"
"Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="2.0.0"
我的图书馆也引用了一些软件包:
"MsgPack.Cli" Version="0.9.2"
"System.Xml.XmlSerializer" Version="4.3.0"
当使用构建目标win-x86和win-x64时,我的应用程序运行正常,但是当我为linux-x64和osx-x64构建它时,我的应用程序在运行时会返回以下错误:
无法加载文件或程序集'System.IO.FileSystem,Version = 4.1.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'。定位的程序集的清单定义与程序集引用不匹配。 (HRESULT异常:0x80131040)
我见过其他人得到这个错误,但他的问题的解决方案似乎并不适用于我的情况。我不知道为什么会出现这个错误,我甚至不首先引用System.IO.Filesystem。
我希望我的问题包含帮助人们帮助我的必要信息:)
答案 0 :(得分:1)
我自己设法找到了解决方案。 似乎我移植代码的方式并不完美。 使用ASP.NET Core 2.0,与1.1版相比,所需的依赖性要少得多。
如果有人感兴趣,我所做的就是减少对以下内容的依赖:
"Microsoft.AspNetCore.All" Version="2.0.0"
"Newtonsoft.Json" Version="10.0.3"
我认为“Newtonsoft.Json”现在甚至可能是多余的。
此外,我发现从Visual Studio 2017发布和从Linux终端发布(我使用Windows子系统用于Linux)之间存在差异。 如果我从Visual Studio发布,可执行文件将无法在linux / mac上运行,但如果我从WSL发布,它可以正常工作。
从linuxtermínal发布的命令是
dotnet publish -c Release -r linux-x64
和
dotnet publish -c Release -r osx-x64
分别