使用 GNU Make。我用它来构建我的项目。您所要做的就是在项目根文件夹中创建一个 Makefile。您可以将 Makefile 嵌套在目录中,并拥有一个运行子目录的顶级 Makefile。然后为每个“子项目”文件夹设置 Makefile 并运行任何命令行工具。与 dotnet 核心是 dotnet 。
等等……GNU——“GNU 不是 Unix”,它是一个 Unix/Linux 应用程序……我运行 Windows。好消息是你可以在 Windows 中做到这一点。我正在通过我的 git-bash 安装(Windows 的 git)使用 make.exe。你将不得不去寻找 make 的 cygwin 端口。(google: "make for git-bash") 然后把它安装到你的 cygwin 文件夹下的 bin 目录下。如果你真的想要,你也可以只安装 cygwin。
使用 Gnu-Make 的好处是它是通用的。由于 dotnet 核心与平台无关,因此 Mac/FreeBSD/Linux 的每个环境都可能已经安装了“make”。将它添加到您的 Windows 机器和项目对我来说很有意义。由于您的项目现在可以由每个人以相同的方式构建。
我的一些项目需要使用 dockerfiles 构建 docker 容器,或者 snap 包,部署到测试等...... Make(请原谅双关语)使它变得容易。
这是一个简单项目 Makefile 的示例。单独运行'make'就像说'make all'你可以设置一个像'cd ./subdir; 这样的命令。make' 作为您的 .phoney 指令之一。(谷歌:“Makefile 文档”)
project_drive?=/c/prj
nuget_repo_name?=Local_Nuget_Packages
local_nuget_dir?=$(project_drive)/$(nuget_repo_name)
RELEASE_VERSION:= `grep "<Version>" *.csproj | cut -d '>' -f 2 | cut -d '<' -f 1`
.PHONEY: clean release test doc nuget install debug_nuget debug_install
all: doc MSBuild
test:
./test.sh
MSBuild:
dotnet build
clean:
dotnet clean; dotnet restore
release:
dotnet build -c Release
doc:
doxygen ./Doxyfile.config
nuget: release
dotnet pack -c Release
install:
cp ./bin/Release/*.$(RELEASE_VERSION).nupkg $(local_nuget_dir)
debug_nuget: MSBuild
dotnet pack
debug_install:
cp ./bin/debug/*.$(RELEASE_VERSION).nupkg $(local_nuget_dir)