Open WeihanLi opened 1 year ago
I get this error when trying to AOT publish an app as well.
@WeihanLi - looking at your repro, I found the following:
alpine
Docker image, but you are trying to publish for -r linux-x64
. Instead, you want to publish for -r linux-musl-x64
.<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
in your .csproj. For whatever reason, when you multi-target and pass -f net7.0
on the command line, the NativeAOT MSBuild logic is getting confused and erroring out.To get your project to work, I fixed (1) in your Dockerfile. And then fixed (2) in the .csproj to just <TargetFramework>net7.0</TargetFramework>
. After doing this, I was able to successfully build the Docker file.
I found this issue only happens when referencing a multitargeted project. Referencing a multitargeted NuGet package is fine. My fix:
<!-- TODO: Workaround https://github.com/dotnet/sdk/issues/28169. Remove when fixed. -->
<ItemGroup Condition="'$(PublishAot)'!='true'">
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Server\Grpc.AspNetCore.Server.csproj" />
<ProjectReference Include="..\..\..\src\Grpc.AspNetCore.Web\Grpc.AspNetCore.Web.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(PublishAot)'=='true'">
<PackageReference Include="Grpc.AspNetCore.Server" Version="$(GrpcDotNetPackageVersion)" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="$(GrpcDotNetPackageVersion)" />
</ItemGroup>
Hi @eerhardt , thanks for the help, I can build it success with the following Dockerfile by following your steps:
FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine AS base
LABEL Maintainer="WeihanLi"
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build-env
# Install NativeAOT build prerequisites
RUN apk update && apk add clang gcc lld musl-dev build-base zlib-dev
WORKDIR /app
COPY ./src/ ./src/
COPY ./build/ ./build/
COPY ./Directory.Build.props ./
COPY ./Directory.Build.targets ./
COPY ./Directory.Packages.props ./
WORKDIR /app/src/HTTPie/
RUN dotnet publish -f net7.0 -c Release --use-current-runtime -p:AssemblyName=http -p:PublishAot=true -p:TargetFrameworks=net7.0 -o /app/artifacts
FROM base AS final
COPY --from=build-env /app/artifacts/http /root/.dotnet/tools/http
RUN ln -s /root/.dotnet/tools/http /root/.dotnet/tools/dotnet-http
ENV PATH="/root/.dotnet/tools:${PATH}"
details: https://github.com/WeihanLi/dotnet-httpie/blob/8325008f7b43536efe7088b81436298b3d0448db/Dockerfile
The function did not work as expected even published success, I think it may belong to another problem that needs to be modified in the source code.
Is it a bug for the multi-target project? Feel free to close this if not a bug.
I found this issue only happens when referencing a project. Referencing a multitargeted NuGet package is fine
I had no reference for any project, so not sure if it's the same problem
This error can even be triggered by having a netstandard2.0 project reference. Is there any way to bypass this TFM check as it is producing a lot of false positives?
Describe the bug
Failed to publish aot
publish command:
The errors:
To Reproduce
Code: https://github.com/WeihanLi/dotnet-httpie/tree/105a17b3e7e0a0c00c2c140498fe1c2ffa17ddeb Build the dockerfile for the docker image
CI: https://weihanli.visualstudio.com/Pipelines/_build/results?buildId=5025&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=bd05475d-acb5-5619-3ccb-c46842dbc997
Exceptions (if any)
Further technical details
dotnet --info
CI example: https://weihanli.visualstudio.com/Pipelines/_build/results?buildId=5025&view=logs&j=12f1170f-54f2-53f3-20dd-22fc7dff55f9&t=b939ce2a-e73e-5c6a-458a-4f58c0003587