How do I pass an equal sign when calling a batch script in Powershell?

前端 未结 6 1260
挽巷
挽巷 2020-12-06 05:04

We have a batch file that invokes our MSBuild-based build process. Syntax:

build App Target [ Additional MSBuild Arguments ]

Internally, i

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 05:42

    The answer is that %2 becomes "/p:property" and %3 becomes "value".

    Make this work in your batch file by using BOTH %2 and %3 and insert an = sign between them:

    msbuild.exe %1.msbuild /t:%2=%3 %4 %5 %6 %7 %8 %9
    

    and do not use the quote chars on the command line call. Use:

    build App Target /p:property=value
    

    For additional args with = signs just keep pairing them up.

    I had the same issue with a simple batch file to run youtube-dl where the URL I pass has an = sign in it. solved as :

    @echo off
    REM YTDL audio only
    echo %1=%2
    youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 %1=%2
    

提交回复
热议问题