从文件中获取变量值并附加新的
get variable value from a file and append with new
我有一个包含变量的文件
$versionNumber = "1.0.0
我需要明确地将变量值更改为 "$versionNumber = "user_choice"
"。
#------------------------------------------------
# Pack parameters used to create the .nupkg file.
#------------------------------------------------
# Specify the Version Number to use for the NuGet package. If not specified, the version number of the assembly being packed will be used.
# NuGet version number guidance: https://docs.nuget.org/docs/reference/versioning and the Semantic Versioning spec: http://semver.org/
# e.g. "" (use assembly's version), "1.2.3" (stable version), "1.2.3-alpha" (prerelease version).
$versionNumber = "1.0.0"
# Specify any Release Notes for this package.
# These will only be included in the package if you have a .nuspec file for the project in the same directory as the project file.
$releaseNotes = ""
# Specify a specific Configuration and/or Platform to only create a NuGet package when building the project with this Configuration and/or Platform.
# e.g. $configuration = "Release"
# $platform = "AnyCPU"
$configuration = ""
$platform = ""
任何可能的方法都是可取的。
使用 Get-Content
cmdlet 读取文件,使用正向后视正则表达式查找 versionNumber 变量并替换它。最后,使用 Set-Content
cmdlet 将其写回:
(Get-Content 'youFile.nupkg' -raw) -replace '(?<=$versionNumber\s=).+', '"user_choice"' |
Set-Content 'youFile.nupkg'
没有正则表达式的其他解决方案
(get-content "C:\temp\nuckpkg.txt").Replace('$releaseNotes = ""', '$releaseNotes = "user_choice"') |
set-content "C:\temp\nuckpkg.txt"
您没有正确使用 Martin 建议的代码。
您正在使用 "$env:Version"
,它最终只会被解释为变量值...'"' 是替换语法的一部分。
你应该这样使用它 "'$env:Version'"
.
此致,
Kvprasoon
我有一个包含变量的文件
$versionNumber = "1.0.0
我需要明确地将变量值更改为 "$versionNumber = "user_choice"
"。
#------------------------------------------------
# Pack parameters used to create the .nupkg file.
#------------------------------------------------
# Specify the Version Number to use for the NuGet package. If not specified, the version number of the assembly being packed will be used.
# NuGet version number guidance: https://docs.nuget.org/docs/reference/versioning and the Semantic Versioning spec: http://semver.org/
# e.g. "" (use assembly's version), "1.2.3" (stable version), "1.2.3-alpha" (prerelease version).
$versionNumber = "1.0.0"
# Specify any Release Notes for this package.
# These will only be included in the package if you have a .nuspec file for the project in the same directory as the project file.
$releaseNotes = ""
# Specify a specific Configuration and/or Platform to only create a NuGet package when building the project with this Configuration and/or Platform.
# e.g. $configuration = "Release"
# $platform = "AnyCPU"
$configuration = ""
$platform = ""
任何可能的方法都是可取的。
使用 Get-Content
cmdlet 读取文件,使用正向后视正则表达式查找 versionNumber 变量并替换它。最后,使用 Set-Content
cmdlet 将其写回:
(Get-Content 'youFile.nupkg' -raw) -replace '(?<=$versionNumber\s=).+', '"user_choice"' |
Set-Content 'youFile.nupkg'
没有正则表达式的其他解决方案
(get-content "C:\temp\nuckpkg.txt").Replace('$releaseNotes = ""', '$releaseNotes = "user_choice"') |
set-content "C:\temp\nuckpkg.txt"
您没有正确使用 Martin 建议的代码。
您正在使用 "$env:Version"
,它最终只会被解释为变量值...'"' 是替换语法的一部分。
你应该这样使用它 "'$env:Version'"
.
此致,
Kvprasoon