2017-06-23 236 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