Powershell 명령어에 ';' (semi-colon) 문자가 포함된 경우
제 경우에, msbuild를 수행 시 다음과 같은 식으로 명령을 내릴 때가 있습니다.
MSBuild.exe ConsoleApp1.csproj /property:Platform=x64 /t:Rebuild
그런데, 여기서 다음과 같이 property를 추가하면,
MSBuild.exe ConsoleApp1.csproj /property:Platform=x64;Configuration=Release /t:Rebuild
이런 오류가 발생합니다.
Configuration=Release : The term 'Configuration=Release' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:194
+ ... zorWebApp.csproj /property:Platform=x64;Configuration=Release /t:Rebu ...
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Configuration=Release:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
왜냐하면 ';' 문자가 PowerShell에서는 명령어 구분자로 사용하기 때문에 한 라인에 저렇게 들어가면 "Configuration=Release..." 이후를 또 하나의 PowerShell 명령어로 해석하게 됩니다. 결국 이런 문제를 해결하려면 escape 처리를 해야 하는데 Powershell에서 이때 사용할 수 있는 문자가 바로 backtick(`)입니다. 따라서 위의 명령어를 다음과 같이 바꾸면 됩니다.
MSBuild.exe ConsoleApp1.csproj /property:Platform=x64`;Configuration=Release /t:Rebuild
참고로, 이 글에서 사용한 msbuild 명령어의 경우 그냥 property를 분리시켜 실행해도 됩니다.
MSBuild.exe ConsoleApp1.csproj /property:Platform=x64 /property:Configuration=Release /t:Rebuild
[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]