2017-06-23 102 views
1

我想从versionName自动生成versionCode。 我想删除所有的点。和替换X的为00的MSBuild搜索并替换为xml文件

从2.05.X.20

所以 - > 2050020

我已经开始tackeling的X 00更换 所以我已经添加了follwoing BeforeBuild目标VS的csproj文件:

<Target Name="BeforeBuild"> 
     <!-- find the versionName in the file --> 
     <XmlPeek XmlInputPath="Properties\AndroidManifest.xml" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" Query="manifest/@android:versionName"> 
     <Output TaskParameter="Result" ItemName="FoundVersionName" /> 
     </XmlPeek> 

     <!-- write the replaced versioncode to the file --> 
     <XmlPoke XmlInputPath="Properties\AndroidManifest.xml" Namespaces="&lt;Namespace Prefix='android' Uri='http://schemas.android.com/apk/res/android' /&gt;" 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] ::复制($ {FoundVersionName})。替换( 'X', '00'))
  • $([System.String] ::复制($(FoundVersionName) ).Replace('X','00'))
  • $([System.String] :: Copy($ FoundVersionName).Replace('X','00'))
  • $([System。字符串] ::复制(@FoundVersionName).Replace('X','00'))
  • $([System.String] :: Copy(FoundVersionName).Replace('X','00'))

但他们都没有工作

如果我使用

  • $(FoundVersionName)

安卓的versionCode被替换2.05.X.20

有什么想法?

回答

2

您用于替换的语法是正确的,但它需要可通过$()语法访问的“属性”。但是您的<XmlPeek>任务已配置为返回一个项目。您可以通过更换

<Output TaskParameter="Result" ItemName="FoundVersionName" /> 

<Output TaskParameter="Result" PropertyName="FoundVersionName" /> 
+0

谢谢你改变了这个!就是这样。 – clogwog