Visual Studio下运行PowerShell脚本自动更新项目里AssemblyInfo.cs文件的版本(自增小版本号)并发布到Nuget服务器上
Posted 吃喝玩乐
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Visual Studio下运行PowerShell脚本自动更新项目里AssemblyInfo.cs文件的版本(自增小版本号)并发布到Nuget服务器上相关的知识,希望对你有一定的参考价值。
Visual Studio下运行PowerShell脚本自动更新项目里AssemblyInfo.cs文件的版本(自增小版本号)并发布到Nuget服务器上
附脚本【 update.ps1文件内容】:
$path="PropertiesAssemblyInfo.cs"
$pattern = ‘[assembly: AssemblyVersion("(.*)")]‘
(Get-Content $path) | ForEach-Object{
if($_ -match $pattern){
# We have found the matching line
# Edit the version number and put back.
$fileVersion = [version]$matches[1]
$newVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, ($fileVersion.Revision + 1)
‘[assembly: AssemblyVersion("{0}")]‘ -f $newVersion
} else {
# Output line as is
$_
}
} | Set-Content $path -Encoding utf8
$pattern = ‘[assembly: AssemblyFileVersion("(.*)")]‘
(Get-Content $path) | ForEach-Object{
if($_ -match $pattern){
# We have found the matching line
# Edit the version number and put back.
$fileVersion = [version]$matches[1]
$newVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, ($fileVersion.Revision + 1)
‘[assembly: AssemblyFileVersion("{0}")]‘ -f $newVersion
} else {
# Output line as is
$_
}
} | Set-Content $path -Encoding utf8
nuget pack -Build -OutputFileNamesWithoutVersion
nuget push -Source "http://****" -ApiKey {password} Demo.nupkg
以上是关于Visual Studio下运行PowerShell脚本自动更新项目里AssemblyInfo.cs文件的版本(自增小版本号)并发布到Nuget服务器上的主要内容,如果未能解决你的问题,请参考以下文章
默认情况下如何以管理员身份运行 Visual Studio?
我可以在没有提升权限的情况下从 Visual Studio 运行程序吗?