I am trying to replace a string in a file through a batch file in post-build action of visual studio. The first string is lMkUk=
and the second string (replacement string) is ##DummyValues##
.
While replacing the first string with the second string using a batch file in Visual Studio post-build action, the first string was not replaced properly, but as =##DummyValues##=
; =
was added at the starting and end of the second string.
But if I remove the =
(and make it lMkUk
) at the end of the first string using the same batch file, the string will be replaced successfully. It seems that the =
is the problem in the second string.
Here is my code:
@echo on&setlocal
setlocal enableextensions disabledelayedexpansion
::License key replacement file
set sourceFile=%1
::Replacement string
set FirstVariable=lMkUk=
set SecondVariable=##DummyValues##
::Replacement statement
if NOT "%FirstVariable%" == "" (
for /f "delims=" %%i in ('type "%sourceFile%" ^& break ^> "%sourceFile%" ') do (
set "line=%%i"
setlocal enabledelayedexpansion
>>"%sourceFile%" echo(!line:%FirstVariable%=%SecondVariable%!
endlocal
)
)
How to resolve this in Visual Studio post-build action?