On macOS I am trying to cross platform build to linux/amd64
Dockerfile
#This target builds the API server and runs unit tests
#-amd64 version locks up during dotnet tool restore on a mac
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS base
#The environment value is case sensitive
ENV ASPNETCORE_ENVIRONMENT=Production
RUN export PATH="$PATH:/root/.dotnet/tools"
RUN apk add --update --no-cache libintl libxml2-utils bc
FROM base as copy-files
WORKDIR /app_build
WORKDIR /app_build/dotnet_tool_issue
# Ensure that global.json file is set to the same .NET version being used in the Dockerfile and vice versa.
COPY . .
COPY ./.config ./.config
#Restore
FROM copy-files as restore
LABEL type="build"
WORKDIR /app_build/dotnet_tool_issue
RUN dotnet tool restore
Docker build command
docker build --platform linux/amd64 -t dotnet_tools_issue .
I get the error
Unhandled exception:Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type NuGet.Protocol.Model.RegistrationIndex. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path '@id', line 1, position 7.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
at NuGet.Protocol.PackageMetadataResourceV3.DeserializeStreamDataAsync[T](Stream stream, CancellationToken token)
at NuGet.Protocol.PackageMetadataResourceV3.<>c__DisplayClass9_0.<<LoadRegistrationIndexAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at NuGet.Protocol.HttpSource.<>c__DisplayClass15_0`1.<<GetAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
at NuGet.Common.ConcurrencyUtilities.ExecuteWithFileLockedAsync[T](String filePath, Func`2 action, CancellationToken token)
at NuGet.Protocol.HttpSource.GetAsync[T](HttpSourceCachedRequest request, Func`2 processAsync, ILogger log, CancellationToken token)
at NuGet.Protocol.PackageMetadataResourceV3.LoadRegistrationIndexAsync(HttpSource httpSource, Uri registrationUri, String packageId, SourceCacheContext cacheContext, Func`2 processAsync, ILogger log, CancellationToken token)
at NuGet.Protocol.PackageMetadataResourceV3.GetMetadataAsync(String packageId, Boolean includePrerelease, Boolean includeUnlisted, VersionRange range, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token)
at NuGet.Protocol.PackageMetadataResourceV3.GetMetadataAsync(String packageId, Boolean includePrerelease, Boolean includeUnlisted, SourceCacheContext sourceCacheContext, ILogger log, CancellationToken token)
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetPackageMetadataAsync(PackageSource source, String packageIdentifier, Boolean includePrerelease, Boolean includeUnlisted, CancellationToken cancellationToken)
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetPackageMetadataAsync(String packageIdentifier, NuGetVersion packageVersion, IEnumerable`1 sources, CancellationToken cancellationToken, Boolean includeUnlisted)
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.GetPackageSourceAndVersion(PackageId packageId, NuGetVersion packageVersion, PackageSourceLocation packageSourceLocation, Boolean includePreview, Boolean includeUnlisted, PackageSourceMapping packageSourceMapping)
at Microsoft.DotNet.Cli.NuGetPackageDownloader.NuGetPackageDownloader.DownloadPackageAsync(PackageId packageId, NuGetVersion packageVersion, PackageSourceLocation packageSourceLocation, Boolean includePreview, Boolean includeUnlisted, Nullable`1 downloadFolder, PackageSourceMapping packageSourceMapping)
at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.DownloadAndExtractPackage(PackageLocation packageLocation, PackageId packageId, INuGetPackageDownloader nugetPackageDownloader, String packagesRootPath, IToolPackageStore toolPackageStore, NuGetVersion packageVersion, PackageSourceLocation packageSourceLocation, Boolean includeUnlisted)
at Microsoft.DotNet.Cli.ToolPackage.ToolPackageDownloader.<>c__DisplayClass8_0.<InstallPackage>b__0()
at Microsoft.DotNet.Cli.TransactionalAction.Run[T](Func`1 action, Action commit, Action rollback)
at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.InstallPackages(ToolManifestPackage package, Nullable`1 configFile)
at System.Linq.Enumerable.SelectArrayIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Microsoft.DotNet.Tools.Tool.Restore.ToolRestoreCommand.Execute()
at System.CommandLine.Invocation.InvocationPipeline.Invoke(ParseResult parseResult)
at Microsoft.DotNet.Cli.Program.ProcessArgs(String[] args, TimeSpan startupTime, ITelemetry telemetryClient)
The FROM line of the Docker file needs to include the platform option.
#This target builds the API server and runs unit tests
#-amd64 version locks up during dotnet tool restore on a mac
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS base
#The environment value is case sensitive
ENV ASPNETCORE_ENVIRONMENT=Production
RUN export PATH="$PATH:/root/.dotnet/tools"
# libintl libxml2-utils bc are needed for the coverage.sh script
RUN apk add --update --no-cache libintl libxml2-utils bc
#Copy files - Copy in just the solution and csproj files which change infrequently
# so that we can do dotnet restore and have that layer cached.
FROM base as copy-files
ARG SOLUTION_NAME="Precisely.Identity.Api"
WORKDIR /app_build
WORKDIR /app_build/dotnet_tool_issue
# Ensure that global.json file is set to the same .NET version being used in the Dockerfile and vice versa.
COPY . .
COPY ./.config ./.config
#Restore
FROM copy-files as restore
LABEL type="build"
WORKDIR /app_build/dotnet_tool_issue
RUN dotnet tool restore -v diag