如何将值从VBScript传递到MSBuild属性?

时间:2014-01-22 14:51:05

标签: vbscript msbuild

我有一个vbscript,它返回我的可执行文件的产品版本。

GetProductVersion.vbs

Option Explicit 
Dim aFileFullPath, aDetail, Result
aFileFullPath = "PATH_TO_MY_EXE_FILE"
aDetail = "Product Version"
Result=fGetFileDetail(aFileFullPath, aDetail)
wscript.echo Result

Function fGetFileDetail(aFileFullPath, aDetail)
    Dim pvShell, pvFileSystemObject, pvFolderName, pvFileName, pvFolder, pvFile, i
    Set pvFileSystemObject = CreateObject("Scripting.FileSystemObject")

    If pvFileSystemObject.FileExists(aFileFullPath) Then
         pvFolderName = pvFileSystemObject.GetFile(aFileFullPath).ParentFolder
         pvFileName = pvFileSystemObject.GetFile(aFileFullPath).Name

         Set pvShell = CreateObject("Shell.Application")
         Set pvFolder = pvShell.Namespace(pvFolderName)
         Set pvFile = pvFolder.ParseName(pvFileName)

         fGetFileDetail = "Detail not detected"

         For i = 0 To 399
              If uCase(pvFolder.GetDetailsOf(pvFolder.Items, i)) = uCase(aDetail) Then
                   fGetFileDetail = pvFolder.GetDetailsOf(pvFile, i)
              End If
         Next
    Else
         fGetFileDetail = "File not found"
    End If
End Function

如果我运行这个脚本,它会告诉我正确的结果 - 在我的情况下是5.1.0.35,所以脚本本身工作正常。但我想在MSBuild中运行此脚本并设置它将返回到MSBuild属性的值。

换句话说,我有一个在我的Msbuild proj文件中定义了默认值的属性:

<PropertyGroup>
     <ProdVersion>5.1.0.0</ProdVersion>
............
</PropertyGroup>

但稍后它的值(5.1.0.0)应该替换为 GetProductVersion.vbs 执行的结果:

我知道,我可以像这样运行vbs:

<Target Name="SetProductVersion">
     <Exec Command="&quot;$(PathToVbScripts)\GetProductVersion.vbs&quot;" />
....

但是如何将 ProdVersion 属性设置为GetProductVersion.vbs将返回的值?

0 个答案:

没有答案