在 .NET project.json 文件中使用 GIT 输出到文件
Output to file using GIT in .NET project.json file
我正在尝试在编译之前将 git 命令输出保存到一个 asp.net 核心项目的文件中。
在 "project.json" 文件中我有以下内容,它应该将最新的 git 标记输出到输出文件(用于版本控制):
"scripts": {
"precompile": [
"git describe --tags > version.txt"
]
},
git 命令在 git bash 中正常运行并保存到文件中。但是当我在 Visual Studio 中编译项目时, 大于符号 似乎有问题。这应该以某种方式逃脱吗?错误显示:“fatal: Not a valid object name >”
完整错误:
"C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : fatal: Not a valid object name >"
有什么想法吗?
请尝试创建包含相同命令的 cmd 脚本(即 update_version.cmd):
git describe --tags > version.txt
更新您的 project.json:
"scripts": {
"precompile": "update_version.cmd"
},
你试过了吗
"scripts": {
"precompile": [
"bash -c 'git describe --tags > version.txt'"
]
},
我最终做的有点像 Ivan 建议的那样,即 运行 一个 cmd 脚本,但也会生成一个带有版本号的 JSON 文件。
这可能比普通文本文件更好,因为 Json 可以从 dotnet 核心中的新配置选项 (OptionsConfigurationServiceCollectionExtensions) 中读取。
不是问题的确切答案,但可能会对其他人有所帮助。
这是生成 appsettingsversion.json 文件的 CMD:
project.json:
"scripts": {
"prepublish": [ "bower install", "dotnet bundle", "update_version.cmd" ]
}
update_version.cmd:
for /f %%i in ('git describe --tags') do set version=%%i
echo {^"VersionSettings^":{^"Number^": ^"%version%^"}} > appsettingsversion.json
我正在尝试在编译之前将 git 命令输出保存到一个 asp.net 核心项目的文件中。
在 "project.json" 文件中我有以下内容,它应该将最新的 git 标记输出到输出文件(用于版本控制):
"scripts": {
"precompile": [
"git describe --tags > version.txt"
]
},
git 命令在 git bash 中正常运行并保存到文件中。但是当我在 Visual Studio 中编译项目时, 大于符号 似乎有问题。这应该以某种方式逃脱吗?错误显示:“fatal: Not a valid object name >”
完整错误: "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets(262,5): error : fatal: Not a valid object name >"
有什么想法吗?
请尝试创建包含相同命令的 cmd 脚本(即 update_version.cmd):
git describe --tags > version.txt
更新您的 project.json:
"scripts": {
"precompile": "update_version.cmd"
},
你试过了吗
"scripts": {
"precompile": [
"bash -c 'git describe --tags > version.txt'"
]
},
我最终做的有点像 Ivan 建议的那样,即 运行 一个 cmd 脚本,但也会生成一个带有版本号的 JSON 文件。
这可能比普通文本文件更好,因为 Json 可以从 dotnet 核心中的新配置选项 (OptionsConfigurationServiceCollectionExtensions) 中读取。
不是问题的确切答案,但可能会对其他人有所帮助。 这是生成 appsettingsversion.json 文件的 CMD:
project.json:
"scripts": {
"prepublish": [ "bower install", "dotnet bundle", "update_version.cmd" ]
}
update_version.cmd:
for /f %%i in ('git describe --tags') do set version=%%i
echo {^"VersionSettings^":{^"Number^": ^"%version%^"}} > appsettingsversion.json