在Linux Docker容器中编译使用Bond的.NET应用程序。

huangapple go评论59阅读模式
英文:

Compile .NET app that uses Bond in Linux Docker container

问题

我尝试为使用Bond的库制作CD。它在本地编译完美,但似乎无法在Docker镜像中编译。我遇到了下面的错误。它建议我需要安装Bond工具。我找不到已安装它们的镜像,也找不到安装它们的方法。(我尝试过apt-getnuget install。)Bond的GitHub项目只展示了如何编译它们。我该如何解决这个问题?

我正在使用镜像mcr.microsoft.com/dotnet/sdk。它可以很好地编译不包含Bond的一切。

MSBuild版本17.5.0-preview-23061-01+040e2a90e用于.NET
  确定要还原的项目...
  已还原/var/workdir/aaa/bbb.csproj(用时11.23秒)。
  /bin/sh:2:/tmp/MSBuildTemproot/tmp07e2245471a6416d99ff3965ff6cc96e.exec.cmd:/app/.nuget/packages/bond.csharp/9.0.5/build/../tools/gbc.exe:执行格式错误
/app/.nuget/packages/bond.csharp/9.0.5/build/Common.targets(161,5):错误MSB3073:命令""/app/.nuget/packages/bond.csharp/9.0.5/build/../tools/gbc.exe" c# --import-dir="/app/.nuget/packages/bond.csharp/9.0.5/build/../tools/inc"  --jobs=-2 --namespace=bond=Bond --output-dir="obj/Release/netstandard2.1/" --using="DateTime=System.DateTime" @"obj/Release/netstandard2.1/bonddefaultcodegen.in""退出,代码为126。[/var/workdir/aaa/bbb.csproj]

生成失败。
英文:

I'm trying to make a CD for a library that uses Bond. It compiles perfectly locally but it seems like I can't compile it in a Docker image. I'm getting the error below. It suggests that I need to install Bond tools. I can't find an image that would have them installed and I also can't find the way to install them. (I did try apt-get and nuget install.) The Bond GitHub project only shows how to compile them. How can I solve that?

I'm using the image mcr.microsoft.com/dotnet/sdk. It compiles everything that don't contain Bond very well.

        MSBuild version 17.5.0-preview-23061-01+040e2a90e for .NET
          Determining projects to restore...
          Restored /var/workdir/aaa/bbb.csproj (in 11.23 sec).
          /bin/sh: 2: /tmp/MSBuildTemproot/tmp07e2245471a6416d99ff3965ff6cc96e.exec.cmd: /app/.nuget/packages/bond.csharp/9.0.5/build/../tools/gbc.exe: Exec format error
        /app/.nuget/packages/bond.csharp/9.0.5/build/Common.targets(161,5): error MSB3073: The command ""/app/.nuget/packages/bond.csharp/9.0.5/build/../tools/gbc.exe" c# --import-dir="/app/.nuget/packages/bond.csharp/9.0.5/build/../tools/inc"  --jobs=-2 --namespace=bond=Bond --output-dir="obj/Release/netstandard2.1/" --using="DateTime=System.DateTime" @"obj/Release/netstandard2.1/bonddefaultcodegen.in"" exited with code 126. [/var/workdir/aaa/bbb.csproj]
        
        Build FAILED.```

</details>


# 答案1
**得分**: 2

看起来您正在尝试在Linux上运行Windows版本的gbc。截至2023年3月,尚无适用于Linux的预编译版本的gbc。NuGet包中包含的gbc仅适用于Windows。

您需要按照[Bond的README](https://github.com/microsoft/bond/blob/master/README.md)中的说明自行编译gbc,以目标为Linux,并设置环境变量(或MSBuild属性)`BOND_COMPILER_PATH`的路径为您已经构建的gbc所在的目录。

这是Bond工具中已知的不足之处。有关更多详细信息,请参阅其GitHub问题#940,标题为“gbc for Linux?”(https://github.com/microsoft/bond/issues/940)。

<details>
<summary>英文:</summary>

It looks like you are trying to run the Windows version of gbc on Linux. As of March 2023, there is no pre-compiled version of gbc for Linux. The gbc included in the NuGet packages is only for Windows.

You will need to compile gbc yourself targeting Linux following the instructions in [Bond&#39;s README](https://github.com/microsoft/bond/blob/master/README.md) and set [the environment variable (or MSBuild property) `BOND_COMPILER_PATH`](https://github.com/microsoft/bond/blob/b13fee1b760119a79d038e43fb05d88e800fc7e5/cs/build/nuget/Common.targets#L8) to the path to the directory that contains the gbc that you have built.

This is a known gap in Bond&#39;s tooling. See its GitHub [issue #940, gbc for Linux?](https://github.com/microsoft/bond/issues/940) for more details.

</details>



huangapple
  • 本文由 发表于 2023年3月4日 04:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75631473.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定