Search code examples
visual-studiobatch-filejenkinsdotfuscator

spaces in dotfuscator in/out paths


I have a very annoying problem regarding dotfuscator and paths with spaces. I have a .bat file that is called via post-build event with the following syntax:

call "$(SolutionDir)..\Build\dotf.bat" $(SolutionDir) $(ConfigurationName) $(TargetPath) $(TargetDir). 

The .bat file looks like this:

SET DOTFPATH="%1..\Tools\DotfuscatorProEdition4.13.0\dotfuscator.exe"
SET DEBUG=%2
SET TARGETFILE=%3
SET OUTPUT=%4

if "%DEBUG%" == "Release" (
    %DOTFPATH% /q /in:"%TARGETFILE%" /out:"%OUTPUT%"
) ELSE (
    echo DOTFUSCATOR: Skipped due to debugmode
)

The .bat file recieves the arguments and generates a command like this:

"C:\some\path\to\dotfuscator.exe" /q /in:C:\a\path\toproject\Mydll.dll /out:C:\a\path\toproject\

the .bat file works great locally. But on the buildserver the solution and project paths have whitespaces, like this:

"C:\some\path\to\dotfuscator.exe" /q /in:C:\a\path\to project\Mydll.dll /out:C:\a\path\to project\

which ofcourse messes up the arguments. So, i tried to enclose the paths with quotationmarks like this:

"C:\some\path\to\dotfuscator.exe" /q /in:"C:\a\path\to project\Mydll.dll" /out:"C:\a\path\to project\"

This fixes the .bat file and the argument parsing, but dotfuscator itself is now failing miserably! Dotfuscator now complains about "Illegal characters in path". How do i fix this?


Solution

  • If the path contains spaces then the parameters passed to the bat file should already be protected with quotes. So you're probably creating /in:""c:\some path"" which won't work. First try removing the quotes on your dotfuscator line in the bat file.

    Alternatively, try changing to the directory and back instead of trying to work out dotfuscator. You'd need to change the 3rd parameter also from targetpath to targetfile

    SET DOTFPATH="%1..\Tools\DotfuscatorProEdition4.13.0\dotfuscator.exe"
    SET DEBUG=%2
    SET TARGETFILE=%3
    SET OUTPUT=%4
    
    if "%DEBUG%" == "Release" (
        pushd %OUTPUT%
        %DOTFPATH% /q /in:%TARGETFILE% /out:.
        popd
    ) ELSE (
        echo DOTFUSCATOR: Skipped due to debugmode
    )