我想从版本名称自动生成版本代码。 我想删除所有点。并将 X 替换为 00
所以从 2.05.X.20 -> 2050020
我已经开始解决 X 到 00 的替换问题 因此,在 VS csproj 文件中,我添加了以下 BeforeBuild 目标:
<Target Name="BeforeBuild">
<!-- find the versionName in the file -->
<XmlPeek XmlInputPath="Properties\AndroidManifest.xml" Namespaces="<Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' />" Query="manifest/@android:versionName">
<Output TaskParameter="Result" ItemName="FoundVersionName" />
</XmlPeek>
<!-- write the replaced versioncode to the file -->
<XmlPoke XmlInputPath="Properties\AndroidManifest.xml" Namespaces="<Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' />" Query="manifest/@android:versionCode"
Value="$([System.String]::Copy($(FoundVersionName)).Replace('X','00')) " />
</Target>
但是输出看起来像
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="$(FoundVersionName)" android:versionName="2.05.X.20" android:installLocation="auto" package="mtdata_taxi_tablet.mtdata_taxi_tablet">
我已经尝试过
- $([System.String]::Copy(${FoundVersionName}).Replace('X','00'))
- $([System.String]::Copy($(FoundVersionName)).Replace('X','00'))
- $([System.String]::Copy($FoundVersionName).Replace('X','00'))
- $([System.String]::Copy(@FoundVersionName).Replace('X','00'))
- $([System.String]::Copy(FoundVersionName).Replace('X','00'))
但它们都不起作用
如果我使用
- $(FoundVersionName)
android:versionCode 替换为 2.05.X.20
有什么想法吗?
最佳答案
您用于替换的语法是正确的,但它需要一个可通过 $()
访问的“属性”句法。但是你的<XmlPeek>
任务配置为返回一个项目。您可以通过替换来更改此设置
<Output TaskParameter="Result" ItemName="FoundVersionName" />
与
<Output TaskParameter="Result" PropertyName="FoundVersionName" />
关于android - MSBuild 在 xml 文件中搜索并替换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44714069/