[英]Nuget package Microsoft.TypeScript.MSBuild fails in Dockerfile
I have an ASP.NET Core project that includes several TypeScript files.我有一个包含多个 TypeScript 文件的 ASP.NET Core 项目。 The project has Microsoft.TypeScript.MSBuild reference to automatically compile these TS files to JavaScript files.
该项目具有Microsoft.TypeScript.MSBuild引用,可自动将这些 TS 文件编译为 JavaScript 文件。
<ItemGroup>
<PackageReference Include="Microsoft.TypeScript.MSBuild" Version="3.2.3" />
</ItemGroup>
The setting worked until I tried to dockerize my project.该设置一直有效,直到我尝试对我的项目进行 dockerize。 When I follow the example here , the error occurs:
当我按照此处的示例进行操作时,会发生错误:
/root/.nuget/packages/microsoft.typescript.msbuild/3.2.3/tools/Microsoft.TypeScript.targets(305,5): error MSB6003: The specified task executable "node" could not be run.
/root/.nuget/packages/microsoft.typescript.msbuild/3.2.3/tools/Microsoft.TypeScript.targets(305,5):错误 MSB6003:无法运行指定的任务可执行文件“节点”。 No such file or directory [/app/MyProject.csproj] The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
没有这样的文件或目录 [/app/MyProject.csproj] 命令“/bin/sh -c dotnet publish -c Release -o out”返回非零代码:1
How to resolve the issue?如何解决问题?
On Windows, Microsoft.TypeScript.MSBuild
includes tsc.exe.在 Windows 上,
Microsoft.TypeScript.MSBuild
包括 tsc.exe。 On non-Windows platforms, such as in a Docker container, Microsoft.TypeScript.MSBuild
does not include ts.exe and instead shells out to a Node for the TypeScript compiler.在非 Windows 平台上,例如在 Docker 容器中,
Microsoft.TypeScript.MSBuild
不包含 ts.exe,而是外壳到 TypeScript 编译器的节点。 The official dotnet/sdk Docker images I think included Node at one point in the past, but they no longer include Node.我认为官方的 dotnet/sdk Docker 镜像过去曾包含 Node,但它们不再包含 Node。 You will either need to make or find a Docker image with both the dotnet-sdk and Node, or configure some multi-stage build involving the official Node image.
您需要使用 dotnet-sdk 和 Node 制作或查找 Docker 镜像,或者配置一些涉及官方 Node 镜像的多阶段构建。
Thanks for the question!感谢提问! Saved me from asking it myself.
让我免于自己问。
For me the fix was as simple as running sudo apt-get install nodejs
(Using Ubuntu 18.04)对我来说,修复就像运行
sudo apt-get install nodejs
一样简单(使用 Ubuntu 18.04)
In linux containers You have to install node first.在 linux 容器中您必须先安装节点。 Add the following lines to your dockerfile.
将以下行添加到您的 dockerfile。 Add it before "RUN dotnet build"
在“RUN dotnet build”之前添加它
RUN apt-get update -yq && apt-get upgrade -yq && apt-get install -yq curl git nano
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -yq nodejs build-essential
RUN npm install -g npm
RUN npm install
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.