Asp.net core mvc dotnet还原:检索包时出错。。。缺少元数据根元素

Asp.net core mvc dotnet还原:检索包时出错。。。缺少元数据根元素,asp.net-core-mvc,nuget,dockerfile,docker-build,dotnet-restore,Asp.net Core Mvc,Nuget,Dockerfile,Docker Build,Dotnet Restore,我有一个nuget/docker构建问题,我花了几天的时间进行调试,现在已经没有什么想法了:你知道我为什么会出现以下错误吗 问题在于一个asp.net核心解决方案(其他非常类似的解决方案不受影响):虽然我可以在visual studio 2019中使用docker compose文件构建受影响的解决方案,但它无法使用docker文件,因此docker build命令无法运行 如果我通过在命令提示符下执行以下生成来运行dockerfile: docker build -f MStoreBosGat

我有一个nuget/docker构建问题,我花了几天的时间进行调试,现在已经没有什么想法了:你知道我为什么会出现以下错误吗

问题在于一个asp.net核心解决方案(其他非常类似的解决方案不受影响):虽然我可以在visual studio 2019中使用docker compose文件构建受影响的解决方案,但它无法使用docker文件,因此docker build命令无法运行

如果我通过在命令提示符下执行以下生成来运行dockerfile:

docker build -f MStoreBosGateway/MStoreBosGatewayApi/Dockerfile --pull --no-cache -t mstorebosgateway:0.041 .
然后我得到以下错误:

Step 11/26 : RUN dotnet restore "MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj"
>  ---> Running in 30819cb5db4f
> /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error : An error
> occurred while retrieving package metadata for
> 'System.Text.Encodings.Web.4.5.0' from source
> '/usr/share/dotnet/sdk/NuGetFallbackFolder'.
> [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
> /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error :   Root
> element is missing.
> [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
> The command '/bin/sh -c dotnet restore
> "MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj"'
> returned a non-zero code: 1
我在dockerfile的每一行后面都放了RUN-echo命令,所以看起来是dotnet还原导致了这个问题。如果我单独运行dotnetrestore命令,它将正常运行

为了解决这个问题,我做了很多事情

  • -已从此解决方案和项目中删除obj和bin文件夹
  • -已卸载并重新安装nuget
  • -删除nuget缓存以强制重新下载包
  • -已卸载并重新安装dotnet core SDK
  • -从项目文件中删除了错误消息('System.Text.Encodings.Web.4.5.0)中提到的包(此操作失败) 不会导致任何错误,因此必须是冗余的)。的确如此 不会影响此错误,它会还原此包,因此必须 使用此软件包或可能的系统软件包的其他说明 默认情况下,所有都包括在内
我的同事可以建立这个项目,并已向我发送了一份他可以建立的副本;我在制作他的副本时也遇到了同样的问题,所以假设它是项目外部的东西

如果我在docker文件中的dotnet restore命令中添加“-verbosity detailed”,我已经在输出下面添加了

           GET https://api.nuget.org/v3-flatcontainer/microsoft.extensions.dependencyinjection.abstractions/index.json
           OK https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/index.json 342ms
           GET https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/2.0.0/aspnet.security.oauth.validation.2.0.0.nupkg
           OK https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/2.0.0/aspnet.security.oauth.validation.2.0.0.nupkg 52ms
           GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.authentication/index.json
           GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
     1>/usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error : An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
/usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error :   Root element is missing. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
           OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/index.json 156ms
           GET https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/4.0.1/swashbuckle.aspnetcore.swaggergen.4.0.1.nupkg
           OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/index.json 160ms
           GET https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/4.0.1/swashbuckle.aspnetcore.swaggerui.4.0.1.nupkg
           OK https://api.nuget.org/v3-flatcontainer/automapper/index.json 155ms
           GET https://api.nuget.org/v3-flatcontainer/automapper/8.0.0/automapper.8.0.0.nupkg
           OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/4.0.1/swashbuckle.aspnetcore.swaggergen.4.0.1.nupkg 44ms
           OK https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/4.0.1/swashbuckle.aspnetcore.swaggerui.4.0.1.nupkg 49ms
           GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.apiexplorer/index.json
           GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.core/index.json
           GET https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.dataannotations/index.json
         NuGet.Protocol.Core.Types.FatalProtocolException: An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. ---> NuGet.Packaging.Core.PackagingException: An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. ---> System.Xml.XmlException: Root element is missing.
            at System.Xml.XmlTextReaderImpl.Throw(Exception e)
            at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
            at System.Xml.XmlTextReaderImpl.Read()
            at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
            at NuGet.Packaging.Core.NuspecCoreReaderBase.LoadXml(Stream stream, Boolean leaveStreamOpen)
            at NuGet.Packaging.Core.NuspecCoreReaderBase..ctor(Stream stream, Boolean leaveStreamOpen)
            at NuGet.Packaging.NuspecReader..ctor(Stream stream)
            at NuGet.Protocol.LocalPackageFileCache.GetNuspec(String manifestPath, String expandedPath)
            at NuGet.Protocol.LocalPackageFileCache.<>c__DisplayClass6_1.<GetOrAddNuspec>b__1()
            at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
            at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
            at System.Lazy`1.CreateValue()
            at NuGet.Protocol.LocalV3FindPackageByIdResource.ProcessNuspecReader[T](String id, NuGetVersion version, Func`2 process)
            --- End of inner exception stack trace ---
            --- End of inner exception stack trace ---
            at NuGet.Protocol.LocalV3FindPackageByIdResource.ProcessNuspecReader[T](String id, NuGetVersion version, Func`2 process)
            at NuGet.Protocol.LocalV3FindPackageByIdResource.GetDependencyInfoAsync(String id, NuGetVersion version, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
            at NuGet.Commands.SourceRepositoryDependencyProvider.GetDependenciesCoreAsync(LibraryIdentity match, NuGetFramework targetFramework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
            at NuGet.Commands.SourceRepositoryDependencyProvider.<>c__DisplayClass21_0.<<GetDependenciesAsync>b__0>d.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at NuGet.Commands.SourceRepositoryDependencyProvider.GetDependenciesAsync(LibraryIdentity libraryIdentity, NuGetFramework targetFramework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
            at NuGet.DependencyResolver.ResolverUtility.CreateGraphItemAsync(RemoteMatch match, NuGetFramework framework, SourceCacheContext cacheContext, ILogger logger, CancellationToken cancellationToken)
            at NuGet.DependencyResolver.ResolverUtility.FindLibraryEntryAsync(LibraryRange libraryRange, NuGetFramework framework, String runtimeIdentifier, RemoteWalkContext context, CancellationToken cancellationToken)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.DependencyResolver.RemoteDependencyWalker.CreateGraphNode(LibraryRange libraryRange, NuGetFramework framework, String runtimeName, RuntimeGraph runtimeGraph, Func`2 predicate, GraphEdge`1 outerEdge)
            at NuGet.Commands.ProjectRestoreCommand.WalkDependenciesAsync(LibraryRange projectRange, NuGetFramework framework, String runtimeIdentifier, RuntimeGraph runtimeGraph, RemoteDependencyWalker walker, RemoteWalkContext context, CancellationToken token)
            at NuGet.Commands.ProjectRestoreCommand.TryRestoreAsync(LibraryRange projectRange, IEnumerable`1 frameworkRuntimePairs, NuGetv3LocalRepository userPackageFolder, IReadOnlyList`1 fallbackPackageFolders, RemoteDependencyWalker remoteWalker, RemoteWalkContext context, Boolean forceRuntimeGraphCreation, CancellationToken token, TelemetryActivity telemetryActivity)
            at NuGet.Commands.RestoreCommand.ExecuteRestoreAsync(NuGetv3LocalRepository userPackageFolder, IReadOnlyList`1 fallbackPackageFolders, RemoteWalkContext context, CancellationToken token, TelemetryActivity telemetryActivity)
            at NuGet.Commands.RestoreCommand.ExecuteAsync(CancellationToken token)
            at NuGet.Commands.RestoreRunner.ExecuteAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
            at NuGet.Commands.RestoreRunner.ExecuteAndCommitAsync(RestoreSummaryRequest summaryRequest, CancellationToken token)
            at NuGet.Commands.RestoreRunner.CompleteTaskAsync(List`1 restoreTasks)
            at NuGet.Commands.RestoreRunner.RunAsync(IEnumerable`1 restoreRequests, RestoreArgs restoreContext, CancellationToken token)
            at NuGet.Commands.RestoreRunner.RunAsync(RestoreArgs restoreContext, CancellationToken token)
            at NuGet.Build.Tasks.RestoreTask.ExecuteAsync(ILogger log)
       Done executing task "RestoreTask" -- FAILED.
     1>Done building target "Restore" in project "MStoreBOSGatewayApi.csproj" -- FAILED.
     1>Done Building Project "/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj" (Restore target(s)) -- FAILED.

Build FAILED.

       "/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj" (Restore target) (1) ->
       (Restore target) ->
         /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error : An error occurred while retrieving package metadata for 'System.Text.Encodings.Web.4.5.0' from source '/usr/share/dotnet/sdk/NuGetFallbackFolder'. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
       /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5): error :   Root element is missing. [/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:04.70
The command '/bin/sh -c dotnet restore "MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj" --verbosity detailed' returned a non-zero code: 1

C:\Applications\VB2017Apps\MStoreBOSGateway>
GEThttps://api.nuget.org/v3-flatcontainer/microsoft.extensions.dependencyinjection.abstractions/index.json
好啊https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/index.json 342ms
得到https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/2.0.0/aspnet.security.oauth.validation.2.0.0.nupkg
好啊https://api.nuget.org/v3-flatcontainer/aspnet.security.oauth.validation/2.0.0/aspnet.security.oauth.validation.2.0.0.nupkg 52毫秒
得到https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.authentication/index.json
得到https://api.nuget.org/v3-flatcontainer/newtonsoft.json/10.0.2/newtonsoft.json.10.0.2.nupkg
1> /usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5):错误:从源“/usr/share/dotnet/sdk/NuGetFallbackFolder”检索“System.Text.Encodings.Web.4.5.0”的包元数据时出错。[/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
/usr/share/dotnet/sdk/2.2.402/NuGet.targets(123,5):错误:缺少根元素。[/src/MStoreBOSGateway/MStoreBOSGatewayApi/MStoreBOSGatewayApi.csproj]
好啊https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/index.json 156ms
得到https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/4.0.1/swashbuckle.aspnetcore.swaggergen.4.0.1.nupkg
好啊https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/index.json 160毫秒
得到https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/4.0.1/swashbuckle.aspnetcore.swaggerui.4.0.1.nupkg
好啊https://api.nuget.org/v3-flatcontainer/automapper/index.json 155ms
得到https://api.nuget.org/v3-flatcontainer/automapper/8.0.0/automapper.8.0.0.nupkg
好啊https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggergen/4.0.1/swashbuckle.aspnetcore.swaggergen.4.0.1.nupkg 44毫秒
好啊https://api.nuget.org/v3-flatcontainer/swashbuckle.aspnetcore.swaggerui/4.0.1/swashbuckle.aspnetcore.swaggerui.4.0.1.nupkg 49毫秒
得到https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.apiexplorer/index.json
得到https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.core/index.json
得到https://api.nuget.org/v3-flatcontainer/microsoft.aspnetcore.mvc.dataannotations/index.json
NuGet.Protocol.Core.Types.FatalProtocolException:从源“/usr/share/dotnet/sdk/NuGetFallbackFolder”检索“System.Text.Encodings.Web.4.5.0”的包元数据时出错。“-->NuGet.Packaging.Core.PackagingException:从源“/usr/share/dotnet/sdk/NuGetFallbackFolder”检索“System.Text.Encodings.Web.4.5.0”的包元数据时出错。“-->System.Xml.XmlException:缺少根元素。
位于System.Xml.XmlTextReaderImpl.Throw(异常e)
位于System.Xml.XmlTextReaderImpl.ParseDocumentContent()处
位于System.Xml.XmlTextReaderImpl.Read()处
位于System.Xml.Linq.XDocument.Load(XmlReader阅读器,LoadOptions)
在NuGet.Packaging.Core.nuspeccorerereaderbase.LoadXml(Stream-Stream,Boolean-leaveStreamOpen)
在NuGet.Packaging.Core.nuspeccorerereaderbase..ctor(Stream-Stream,Boolean-leaveStreamOpen)
在NuGet.Packaging.NuspecReader..ctor(流)
位于numget.Protocol.LocalPackageFileCache.GetNuspec(字符串manifestPath,字符串expandedPath)
在NuGet.Protocol.LocalPackageFileCache.c__DisplayClass6_1.b__1()中
在System.Lazy`1.ViaFactory(LazyThreadSafetyMode模式)
位于System.Lazy`1.ExecutionAndPublication(LazyHelper ExecutionAndPublication,布尔useDefaultConstructor)
在System.Lazy`1.CreateValue()处
在NuGet.Protocol.LocalV3FindPackageByIdResource.ProcessNuspecReader[T](字符串id,NuGetVersion版本,Func`2进程)
---内部异常堆栈跟踪的结束---
---内部异常堆栈跟踪的结束---
在NuGet.Protocol.LocalV3FindPackageByIdResource.ProcessNuspecReader[T](St