我有一个容器运行图像
mcr.microsoft.com/dotnet/sdk:7.0
。
我想用实体框架生成一个数据库迁移脚本。所以最后我想运行这个命令。
dotnet ef migrations add Initial --project Source\Path\To\My.csproj
这就是我所做的:
运行容器
docker run -dti --name ProjectName.Build.Container -v "ProjectSourceDir:/code" mcr.microsoft.com/dotnet/sdk:7.0
安装
dotnet-ef
工具
docker exec -it ProjectName.Build.Container dotnet tool install --global dotnet-ef
输出为:
Tools directory '/root/.dotnet/tools' is not currently on the PATH environment variable. If you are using bash, you can add it to your profile by running the following command: cat << \EOF >> ~/.bash_profile # Add .NET Core SDK tools export PATH="$PATH:/root/.dotnet/tools" EOF You can add it to the current session by running the following command: export PATH="$PATH:/root/.dotnet/tools" You can invoke the tool using the following command: dotnet-ef Tool 'dotnet-ef' (version '7.0.5') was successfully installed.
迁移
docker exec -it Projectname.Build.Container dotnet ef migrations add Initial --project /code/Source/Path/To/My.csproj
但是我得到以下错误
Could not execute because the specified command or file was not found. Possible reasons for this include: * You misspelled a built-in dotnet command. * You intended to execute a .NET program, but dotnet-ef does not exist. * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
但是我无法将
/root/.dotnet/tools
添加到我的Path
中,因为/root
目录是空的。而/home
目录也是空的。
我能做些什么来解决这个问题?
当我
sh
进入容器时,这是dotnet tool list -g
的输出
# dotnet tool list -g
Package Id Version Commands
--------------------------------------
dotnet-ef 7.0.5 dotnet-ef
这是
dotnet --info
的输出
.NET SDK:
Version: 7.0.203
Commit: 5b005c19f5
Runtime Environment:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: debian.11-x64
Base Path: /usr/share/dotnet/sdk/7.0.203/
Host:
Version: 7.0.5
Architecture: x64
Commit: 8042d61b17
.NET SDKs installed:
7.0.203 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
顺便说一句。我在 Synology NAS 上运行 docker。