从MSBUILD脚本中提取RAR

时间:2013-09-25 18:56:24

标签: msbuild rar

我知道使用MSBuild扩展包我可以解压缩Zip文件,但在我的项目中我需要解压缩一个RAR文件。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

使用Exec通过winrar.exe / rar.exe解压缩归档。 如果您已经安装了WinRar,则可以从注册表中提取其installdir,否则请指定rar.exe所在的位置。

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">

<Target Name="ExtractRar">
    <PropertyGroup>
        <RarExe>$(registry:HKEY_LOCAL_MACHINE\Software\Winrar@exe32)</RarExe>
        <archive>E:\sample.rar</archive>
        <targetDir>E:\ExtratedArchive\</targetDir>
    </PropertyGroup>
    <Exec Command="&quot;$(RarExe)&quot; x &quot;$(archive)&quot; &quot;$(targetDir)&quot;" /> 
</Target>

</Project>