2013-10-23 2 views
1

저는 안드로이드 프로젝트 용 apk 빌드를 자동화하기 위해 powershell 스크립트를 실행하고 있습니다. 내 빌드 스크립트가 AndroidManifest.xml 파일의 매개 변수를 대체하는 데 사용할 앱 버전 코드와 이름을 전달할 수 있습니다.Powershell regex는 한 줄에서 작동하지만 다른 글꼴은 지원하지 않습니다.

교체해야 할 두 줄이 있습니다. 다음과 같이 XML 파일의 원래 줄은 다음과 같습니다

android:versionCode="1" 
android:versionName="Version 1" 
다음과 같이 내가하고 각 줄의 텍스트를 대체하기 위해 두 개의 서로 다른 명령을 실행하는거야

, 그들은있다 :

(Get-Content "$fullOutputPath\$projectFileName\AndroidManifest.xml") | ForEach-Object {$_ -replace "(android:versionCode=`")1(`")", "`$1$versionCode`$2"} | Set-Content "$fullOutputPath\$projectFileName\AndroidManifest.xml"; 
(Get-Content "$fullOutputPath\$projectFileName\AndroidManifest.xml") | ForEach-Object {$_ -replace "(android:versionName=`")1\.0(`")", "`$1$versionName`$2"} | Set-Content "$fullOutputPath\$projectFileName\AndroidManifest.xml"; 

parametesr을 테스트하려면 VersionCode는 "2"이고 버전 이름은 "Version 1"입니다. 결과 XML 파일은 다음과 같이 나온다 :

$12" 
android:versionName="Version 1" 

그래서 두 번째 정규식은 잘 작동을 대체 볼 수 있듯이, 첫 번째는하지 않습니다. 왜 또는 어떻게 수정해야하는지 이해할 수없는 것 같습니다.

도움 주셔서 감사합니다.

답변

0
는 귀하의 대체 표현을 변경

:이 정규식에 넘겨지기 전에

"`${1}$versionCode`$2" 

PowerShell을 먼저 $versionCode을 대체합니다. 정규식에는 12 달러가 있지만 12 번째 캡처 그룹이 없습니다.

+0

아! 고맙습니다! 그게 효과가 있었어! – kamcknig

관련 문제