ArchLinux安装netcoredbg时dotnet restore报NU1101错误求助
在ArchLinux编译netcoredbg时的NU1101错误解决办法
问题描述
在ArchLinux上做.NET开发,按照ArchWiki的VS Code相关指南编译netcoredbg时,执行makepkg报错。错误是dotnet restore找不到Microsoft.NETCore.App.Host.arch-x64包,但确认Microsoft.NETCore.App.Host.linux-x64包在NuGet源上存在。试过安装NuGet并通过dotnet add package给generrmsg.csproj添加正确包,没用,每次dotnet restore都会触发这个错误。
错误日志
-- Compiler type CLANG: /usr/bin/clang++ -- Configuring done (1.4s) -- Generating done (0.0s) -- Build files have been written to: /home/Weinman/Downloads/netcoredbg/src/netcoredbg-2.2.3-992/build [ 5%] Built target linenoise [ 7%] Built target example [ 21%] Built target corguids [ 21%] Built target buildinfo [ 22%] Compiling generrmsg/bin/generrmsg.dll MSBuild version 17.4.8+6918b863a for .NET Determining projects to restore... /home/Weinman/Downloads/netcoredbg/src/netcoredbg-2.2.3-992/build/src/generrmsg/generrmsg.csproj : error NU1101: Unable to find package Microsoft.NETCore.App.Host.arch-x64. No packages exist with this id in source(s): nuget.org Failed to restore /home/Weinman/Downloads/netcoredbg/src/netcoredbg-2.2.3-992/build/src/generrmsg/generrmsg.csproj (in 1,41 sec). ERROR al compilar.
解决方法
1. 临时指定RID编译
直接在执行makepkg时通过环境变量覆盖默认RID:
DOTNET_RUNTIME_ID=linux-x64 makepkg -si
2. 修改系统级dotnet配置
创建或编辑/etc/dotnet/dotnet.defaults文件,添加以下内容:
[netcore] RuntimeIdentifier=linux-x64
这样所有dotnet项目都会默认使用linux-x64作为RID,一劳永逸。
3. 修改单个项目配置
找到编译目录里的generrmsg.csproj,在<PropertyGroup>节点中添加或修改RuntimeIdentifier:
<Project Sdk="Microsoft.NET.Sdk"> <!-- 其他原有配置 --> <PropertyGroup> <RuntimeIdentifier>linux-x64</RuntimeIdentifier> </PropertyGroup> </Project>
原因说明
ArchLinux上的dotnet默认使用arch-x64作为Runtime Identifier(RID),但微软官方NuGet源只提供通用的linux-x64架构包,所以需要强制指定兼容的RID来解决包查找失败的问题。
内容的提问来源于stack exchange,提问作者DaniWein
相关产品推荐
相关产品推荐

