我使用以下定义创建了git-lab yaml文件:
stages:
- increase_build_number
- build
increase_build_number:
image: philippheuer/docker-gitlab-powershell
stage: increase_build_number
script:
# run build version script
- powershell -ExecutionPolicy Bypass -File build-version.ps1
- echo $avBuild
- echo avBuild
build:
image: microsoft/dotnet:latest
stage: build
script:
"dotnet build"
我还创建了Power-shell脚本
$path = "build-version.csproj"
#Read csproj (XML)
$xml = [xml](Get-Content $path)
#Retrieve Version Nodes
$assemblyVersion = $xml.Project.PropertyGroup.AssemblyVersion
#Split the Version Numbers
$avMajor, $avMinor, $avBuild = $assemblyVersion.Split(".")
#Increment Build Version
$avBuild = [Convert]::ToInt32($avBuild,10)+1
#Put new version back into csproj (XML)
$xml.Project.PropertyGroup.AssemblyVersion = "$avMajor.$avMinor.$avBuild"
#Save csproj (XML)
$xml.Save($path)
Write-Host "Updated csproj $path and set to version $avMajor.$avMinor.$avBuild"
Write-Host "$avMajor.$avMinor.$avBuild"
提取自该点以来似乎正常工作的版本内部版本号
$xml.Save($path)
那给我一个错误
$ powershell -ExecutionPolicy Bypass -File build-version.ps1
Starting process of generating new version number for the csproj...
Cannot find an overload for "Save" and the argument count: "1".
At /builds/wwwbranimir/ci-test/build-version.ps1:22 char:1
+ $xml.Save($path)
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodException
+ FullyQualifiedErrorId : MethodCountCouldNotFindBest
我在这里做错了吗?是否可以通过git lab管道更新存储库中的.csproj并更新版本?我想要实现的是更新.csproj,所以最终我在.csproj中有类似的内容
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>build_version</RootNamespace>
<AssemblyVersion>0.4.1</AssemblyVersion>
</PropertyGroup>
</Project>