Search code examples
msbuildrar

Extract RAR from MSBUILD script


I know that using MSBuild Extension Pack I can decompress Zip files, but in my project I need to decompress a RAR file.

How can I do this?


Solution

  • Use Exec to extract archive by winrar.exe/rar.exe. If you have installed WinRar you can extract its installdir from registry otherwise specify where you rar.exe is located.

    <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>