The second day I beat my head against the wall and can not figure it out.
How it is possible to implement this dll, any mistakes constantly jump out.
I tried many different options that are on the Internet. Nothing helped.
Help me figure out how to solve the problem.
How to implement Newtonsoft.Json in my project via ILMerge?
Thank you in advance.
Error:
leave command
""C:\Users\User\Desktop\FastFoodDemo\ILMerge\merge_all.bat"
"C:\Users\User\Desktop\FastFoodDemo\"
"C:\Users\User\Desktop\FastFoodDemo\FastFoodDemo\bin\Debug\RCC.exe"
Debug" with code 1. FastFoodDemo
Event final assembly:
"$(SolutionDir)\ILMerge\merge_all.bat" "$(SolutionDir)" "$(TargetPath)" $(ConfigurationName)
merge_all.bat
#ECHO OFF
rem # set .NET version and output folder name
set net="v4, C:\Windows\Microsoft.NET\Framework\v4.0.30319"
set output=Output
rem # process arguments
set ILMergeSolution=%1ILMerge\ILMerge.exe
rem # determine programm files of x86 for 32 and 64 Platform
IF EXIST "%PROGRAMFILES(x86)%" set prorgammFiles=%PROGRAMFILES(x86)%
IF NOT EXIST "%PROGRAMFILES(x86)%" set prorgammFiles=%PROGRAMFILES%
rem # if ILMerge.exe not in the $(SolutionDir)ILMerge\
rem # then try to use installed in prorgammFiles
IF EXIST %ILMergeSolution% set ILMerge="%ILMergeSolution%"
IF NOT EXIST %ILMergeSolution% set ILMerge=%prorgammFiles%\Microsoft\ILMerge\ILMerge.exe
set target_path=%2
set target_file=%~nx2
set target_dir=%~dp2
set ConfigurationName=%3
rem # set output path and result file path
set outdir=%target_dir%%output%
set result=%outdir%\%target_file%
rem # print info
#echo Start %ConfigurationName% Merging %target_file%.
#echo Target: %target_path%
#echo target_dir: %target_dir%
#echo Config: %ConfigurationName%
rem # recreate outdir
IF EXIST "%outdir%" rmdir /S /Q "%outdir%"
md "%outdir%"
rem # run merge cmd
#echo Merging: '"%ILMerge%" /wildcards /targetplatform:%net% /out:"%result%" %target_path% "%target_dir%*.dll"'
"%ILMerge%" /wildcards /targetplatform:%net% /out:"%result%" %target_path% "%target_dir%*.dll"
rem # if succeded
IF %ErrorLevel% EQU 0 (
rem # clear real output folder and put there result assembly
IF %ConfigurationName%==Release (
del %target_dir%*.*
del %target_dir%*.dll
del %target_dir%*.pdb
del %target_dir%*.xml
del %target_dir%*.*
copy %result% %target_dir%
rmdir /S /Q %outdir%
set result=%target_path%
#echo Result: %target_file% "-> %target_path%"
) ELSE (
#echo Result: %target_file% "-> %result%" )
set status=succeded
set errlvl=0
) ELSE (
set status=failed
set errlvl=1
)
#echo Merge %status%
exit %errlvl%
Related
I'm using Visual Studio 2019 and C# Windows Forms.
I'm trying to execute a batch file that contains the following commands:
C:\\devkitPro\\msys2\\msys2_shell.cmd -mingw32 -c "cd /d/HelloWorld/Assets && make"
There is a Makefile located in the /d/HelloWorld/Assets directory, as well as a C++ source file (*.cpp) and I would like to execute/compile it from my C# app.
NOTE: The batch file is located in the same location as the Makefile.
When I double-click the batch file in File Explorer, it runs and compiles the C++ source code just fine. But, when I run it via Process.Start(), it simply opens then almost instantly closes.
e.x. Process.Start(#"D:\HelloWorld\Assets\batch.bat"); doesn't work. It opens mingw32, but then instantly (or sometimes almost instantly) closes.
I'm not sure what to do next, I'd appreciate anyone's help.
EDIT: This is a long .cmd script, as it is msys2, so here it is:
#echo off
setlocal EnableDelayedExpansion
set "WD=%__CD__%"
if NOT EXIST "%WD%msys-2.0.dll" set "WD=%~dp0usr\bin\"
set "LOGINSHELL=bash"
set /a msys2_shiftCounter=0
rem To activate windows native symlinks uncomment next line
rem set MSYS=winsymlinks:nativestrict
rem Set debugging program for errors
rem set MSYS=error_start:%WD%../../mingw64/bin/qtcreator.exe^|-debug^|^<process-id^>
rem To export full current PATH from environment into MSYS2 use '-use-full-path' parameter
rem or uncomment next line
rem set MSYS2_PATH_TYPE=inherit
:checkparams
rem Help option
if "x%~1" == "x-help" (
call :printhelp "%~nx0"
exit /b %ERRORLEVEL%
)
if "x%~1" == "x--help" (
call :printhelp "%~nx0"
exit /b %ERRORLEVEL%
)
if "x%~1" == "x-?" (
call :printhelp "%~nx0"
exit /b %ERRORLEVEL%
)
if "x%~1" == "x/?" (
call :printhelp "%~nx0"
exit /b %ERRORLEVEL%
)
rem Shell types
if "x%~1" == "x-msys" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MSYS& goto :checkparams
if "x%~1" == "x-msys2" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MSYS& goto :checkparams
if "x%~1" == "x-mingw32" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MINGW32& goto :checkparams
if "x%~1" == "x-mingw64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=MINGW64& goto :checkparams
if "x%~1" == "x-ucrt64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=UCRT64& goto :checkparams
if "x%~1" == "x-clang64" shift& set /a msys2_shiftCounter+=1& set MSYSTEM=CLANG64& goto :checkparams
if "x%~1" == "x-mingw" shift& set /a msys2_shiftCounter+=1& (if exist "%WD%..\..\mingw64" (set MSYSTEM=MINGW64) else (set MSYSTEM=MINGW32))& goto :checkparams
rem Console types
if "x%~1" == "x-mintty" shift& set /a msys2_shiftCounter+=1& set MSYSCON=mintty.exe& goto :checkparams
if "x%~1" == "x-conemu" shift& set /a msys2_shiftCounter+=1& set MSYSCON=conemu& goto :checkparams
if "x%~1" == "x-defterm" shift& set /a msys2_shiftCounter+=1& set MSYSCON=defterm& goto :checkparams
rem Other parameters
if "x%~1" == "x-full-path" shift& set /a msys2_shiftCounter+=1& set MSYS2_PATH_TYPE=inherit& goto :checkparams
if "x%~1" == "x-use-full-path" shift& set /a msys2_shiftCounter+=1& set MSYS2_PATH_TYPE=inherit& goto :checkparams
if "x%~1" == "x-here" shift& set /a msys2_shiftCounter+=1& set CHERE_INVOKING=enabled_from_arguments& goto :checkparams
if "x%~1" == "x-where" (
if "x%~2" == "x" (
echo Working directory is not specified for -where parameter. 1>&2
exit /b 2
)
cd /d "%~2" || (
echo Cannot set specified working diretory "%~2". 1>&2
exit /b 2
)
set CHERE_INVOKING=enabled_from_arguments
rem Ensure parentheses in argument do not interfere with FOR IN loop below.
set msys2_arg="%~2"
call :substituteparens msys2_arg
call :removequotes msys2_arg
rem Increment msys2_shiftCounter by number of words in argument (as cmd.exe saw it).
rem (Note that this form of FOR IN loop uses same delimiters as parameters.)
for %%a in (!msys2_arg!) do set /a msys2_shiftCounter+=1
)& shift& shift& set /a msys2_shiftCounter+=1& goto :checkparams
if "x%~1" == "x-no-start" shift& set /a msys2_shiftCounter+=1& set MSYS2_NOSTART=yes& goto :checkparams
if "x%~1" == "x-shell" (
if "x%~2" == "x" (
echo Shell not specified for -shell parameter. 1>&2
exit /b 2
)
set LOGINSHELL="%~2"
call :removequotes LOGINSHELL
set msys2_arg="%~2"
call :substituteparens msys2_arg
call :removequotes msys2_arg
for %%a in (!msys2_arg!) do set /a msys2_shiftCounter+=1
)& shift& shift& set /a msys2_shiftCounter+=1& goto :checkparams
rem Collect remaining command line arguments to be passed to shell
if %msys2_shiftCounter% equ 0 set SHELL_ARGS=%* & goto cleanvars
set msys2_full_cmd=%*
for /f "tokens=%msys2_shiftCounter%,* delims=,;= " %%i in ("!msys2_full_cmd!") do set SHELL_ARGS=%%j
:cleanvars
set msys2_arg=
set msys2_shiftCounter=
set msys2_full_cmd=
rem Setup proper title and icon
if "%MSYSTEM%" == "MINGW32" (
set "CONTITLE=MinGW x32"
set "CONICON=mingw32.ico"
) else if "%MSYSTEM%" == "MINGW64" (
set "CONTITLE=MinGW x64"
set "CONICON=mingw64.ico"
) else if "%MSYSTEM%" == "UCRT64" (
set "CONTITLE=MinGW UCRT x64"
set "CONICON=ucrt64.ico"
) else if "%MSYSTEM%" == "CLANG64" (
set "CONTITLE=MinGW Clang x64"
set "CONICON=clang64.ico"
) else (
set "CONTITLE=MSYS2 MSYS"
set "CONICON=msys2.ico"
)
if "x%MSYSCON%" == "xmintty.exe" goto startmintty
if "x%MSYSCON%" == "xconemu" goto startconemu
if "x%MSYSCON%" == "xdefterm" goto startsh
if NOT EXIST "%WD%mintty.exe" goto startsh
set MSYSCON=mintty.exe
:startmintty
if not defined MSYS2_NOSTART (
start "%CONTITLE%" "%WD%mintty" -i "/%CONICON%" -t "%CONTITLE%" "/usr/bin/%LOGINSHELL%" --login !SHELL_ARGS!
) else (
"%WD%mintty" -i "/%CONICON%" -t "%CONTITLE%" "/usr/bin/%LOGINSHELL%" --login !SHELL_ARGS!
)
exit /b %ERRORLEVEL%
:startconemu
call :conemudetect || (
echo ConEmu not found. Exiting. 1>&2
exit /b 1
)
if not defined MSYS2_NOSTART (
start "%CONTITLE%" "%ComEmuCommand%" /Here /Icon "%WD%..\..\%CONICON%" /cmd "%WD%\%LOGINSHELL%" --login !SHELL_ARGS!
) else (
"%ComEmuCommand%" /Here /Icon "%WD%..\..\%CONICON%" /cmd "%WD%\%LOGINSHELL%" --login !SHELL_ARGS!
)
exit /b %ERRORLEVEL%
:startsh
set MSYSCON=
if not defined MSYS2_NOSTART (
start "%CONTITLE%" "%WD%\%LOGINSHELL%" --login !SHELL_ARGS!
) else (
"%WD%\%LOGINSHELL%" --login !SHELL_ARGS!
)
exit /b %ERRORLEVEL%
:EOF
exit /b 0
:conemudetect
set ComEmuCommand=
if defined ConEmuDir (
if exist "%ConEmuDir%\ConEmu64.exe" (
set "ComEmuCommand=%ConEmuDir%\ConEmu64.exe"
set MSYSCON=conemu64.exe
) else if exist "%ConEmuDir%\ConEmu.exe" (
set "ComEmuCommand=%ConEmuDir%\ConEmu.exe"
set MSYSCON=conemu.exe
)
)
if not defined ComEmuCommand (
ConEmu64.exe /Exit 2>nul && (
set ComEmuCommand=ConEmu64.exe
set MSYSCON=conemu64.exe
) || (
ConEmu.exe /Exit 2>nul && (
set ComEmuCommand=ConEmu.exe
set MSYSCON=conemu.exe
)
)
)
if not defined ComEmuCommand (
FOR /F "tokens=*" %%A IN ('reg.exe QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ConEmu64.exe" /ve 2^>nul ^| find "REG_SZ"') DO (
set "ComEmuCommand=%%A"
)
if defined ComEmuCommand (
call set "ComEmuCommand=%%ComEmuCommand:*REG_SZ =%%"
set MSYSCON=conemu64.exe
) else (
FOR /F "tokens=*" %%A IN ('reg.exe QUERY "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\ConEmu.exe" /ve 2^>nul ^| find "REG_SZ"') DO (
set "ComEmuCommand=%%A"
)
if defined ComEmuCommand (
call set "ComEmuCommand=%%ComEmuCommand:*REG_SZ =%%"
set MSYSCON=conemu.exe
)
)
)
if not defined ComEmuCommand exit /b 2
exit /b 0
:printhelp
echo Usage:
echo %~1 [options] [login shell parameters]
echo.
echo Options:
echo -mingw32 ^| -mingw64 ^| -ucrt64 ^| -clang64 ^| -msys[2] Set shell type
echo -defterm ^| -mintty ^| -conemu Set terminal type
echo -here Use current directory as working
echo directory
echo -where DIRECTORY Use specified DIRECTORY as working
echo directory
echo -[use-]full-path Use full current PATH variable
echo instead of trimming to minimal
echo -no-start Do not use "start" command and
echo return login shell resulting
echo errorcode as this batch file
echo resulting errorcode
echo -shell SHELL Set login shell
echo -help ^| --help ^| -? ^| /? Display this help and exit
echo.
echo Any parameter that cannot be treated as valid option and all
echo following parameters are passed as login shell command parameters.
echo.
exit /b 0
:removequotes
FOR /F "delims=" %%A IN ('echo %%%1%%') DO set %1=%%~A
GOTO :eof
:substituteparens
SETLOCAL
FOR /F "delims=" %%A IN ('echo %%%1%%') DO (
set value=%%A
set value=!value:^(=x!
set value=!value:^)=x!
)
ENDLOCAL & set %1=%value%
GOTO :eof
This approach will only work in Windows.
System.Diagnostics.Process.Start("explorer.exe", pathToBatFile);
This utilizes File Explorer, and runs the .bat file using File Explorer, and successfully compiles the C++ source code (main.cpp) using the Makefile.
The .bat file contains the following:
call C:\devkitPro\msys2\msys2_shell.cmd -mingw32 -c "cd /d/HelloWorld/Assets && make"
..That will successfully make the Makefile located in D:\HelloWorld\Assets.
NOTE: devkitPro needs to be installed for the .bat and the code to work correctly.
I am using below cmd code to install a windows service
#echo off
:: BatchGotAdmin
::-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"="
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
::--------------------------------------
::ENTER YOUR CODE BELOW:
cmd /k "C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil -i C:\fgbk\WindowsService\installer\OurIntegrationService.exe"
So this creates a service with name OurIntegrationService and i want to create another instance of same service with a different name OurIntegrationServiceStage
How can i do this ?
The ServiceName identifies the service to the Service Control Manager.
The value of this property must be identical to the name recorded for
the service in the ServiceInstaller.ServiceName property of the
corresponding installer class. In code, the ServiceName of the service
is usually set in the main() function of the executable.
https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicebase.servicename?view=netframework-4.7.2
To give a different name, I suggest you change the service (if you have the code) to read name from app.config, or any other config location.
You can also change the display name (not the service name) by directly changing it in registry.
I have a batch file that calls C# program. This C# program makes call to SQL Server database.
Sometimes it is unable to connect to the database and the exception handler prints stack trace and exits c# program. I want to try to run this program maximum of 5 times.
If it succeeds (before 5 tries) then go to next step (CheckStatus) else Error out and quit.
When I run this, It is printing %ERRORLEVEL% as zero even when C# program has an error.
#ECHO OFF
SET Header=-----------------------------------------------------
SET Logfile=C:\LOG\log.txt
set %ERRORLEVEL% = 0
echo %header%
ECHO Running the batch file >> %Logfile%
if '%1' == '' goto usage
if '%2' == '' goto usage
if '%1' == '/?' goto usage
if '%1' == '-?' goto usage
if '%1' == '?' goto usage
if '%1' == '/help' goto usage
SET SQLServer=dbsql\production
SET SQLUser=user1
SET SQLPass=pwd1
SET SQLCommandMaster=osql -S%SQLServer% -n -U%SQLUser% -P%SQLPass% -b -i
GOTO %1%
:Start
Set count=0
:RunCSharpProgram
set /a count+=1
ECHO starting RunCSharpProgram count >> %Logfile%
timeout /t 10
SET RunningStep="RunCSharpProgram"
start "" "C:\CSharpProject\GetData\GetData\bin\Debug\GetData.exe"
ECHO %ERRORLEVEL% >> %Logfile%
IF %ERRORLEVEL% ==1 and count LEQ 5 (GOTO RunCSharpProgram)
IF %ERRORLEVEL% ==1 and count EQ 5 (GOTO error)
IF %ERRORLEVEL% ==0 (GOTO CheckStatus)
:CheckStatus
ECHO Check Status of tables >> %Logfile%
REM %SQLCOMMANDMASTER% /Q "EXEC TestDB.dbo.CheckStatus"
goto end
:usage
echo Usage: %0 'start step' 'end step'
goto end
:error
REM ---------------------------------------------------------------------
ECHO ERROR RUNNING BatchFileTest.BAT >> %Logfile%
:end
echo %header% >> %Logfile%
echo END >> %Logfile%
Not sure what is wrong with this batch file.
Thanks
MR
When you use start, it would start a new shell to run your program.
Official documentation
Starts a separate Command Prompt window to run a specified program or command.
Since it is a separate command prompt you will NOT get back the error codes. So, simple solution do not use the start
instead of
start "" "C:\CSharpProject\GetData\GetData\bin\Debug\GetData.exe"
you can just use
"C:\CSharpProject\GetData\GetData\bin\Debug\GetData.exe"
Here is my attempt to copy my application executable to another folder changing it's name:
IF $(ConfigurationName) == Release (
SET DESTINATION=$(ProjectDir)Output\Distribution
IF NOT EXIST "%DESTINATION%" ( MD "%DESTINATION%" )
XCOPY /Q /Y "$(TargetPath)" "%DESTINATION%"
RENAME "%DESTINATION%\$(TargetFileName)" "$(TargetName).Plain$(TargetExt)"
)
I've tried everything to make it work, but it always throw error code 255 or 1, it depends. Running that code with a plain batch file works like a charm!
You need to enable delayed expansion, using the SETLOCAL EnableDelayedExpansion command. Do it at the top of the post-build event. After that, you can access your variable by using not %VARIABLE_NAME%, but !VARIABLE_NAME! (use an exclamation symbol on either side of the variable name, not the percentage symbol which you would use in a regular batch file).
So, for example
SETLOCAL EnableDelayedExpansion
IF $(ConfigurationName) == Release (
SET DESTINATION=$(ProjectDir)Output\Distribution
echo My destination dir is !DESTINATION!
)
This will output something like
My destination dir is D:\Work\Projects\PBExample\Output\Distribution.
Since the Post-build event command line actually runs as a batch file you need to escape characters like % by doubling them to %%:
https://stackoverflow.com/a/13552702/74585
I would love to have a little problem solved. I know that it's not the best way to debug a piece of code with possible warnings, but I love to debug all the time when I have a little break between to ideas. I just found out about mono and the possibility to compile C# code running on Mac OS X Mountain Lion. I integrated it in the CodeRunner app, and it works without any problems. However, if there appears a warning in the code, it does not work.
For example, I tried to compile a code that creates one integer (nothing more than that) and it was not debugging because of that warning. I'm getting this error message:
Untitled.cs(9,29): warning CS0219: The variable `test' is assigned but its value is never used
Cannot open assembly 'Compilation succeeded - 1 warning(s)
Untitled.exe': No such file or directory.
Someone may know how to deal with that. I know it's not an essential feature, but I would love to debug the code even with some unused variables.
The content of the compilation script file:
#!/bin/bash
enc[4]="UTF8" # UTF-8
enc[10]="UTF16" # UTF-16
enc[5]="ISO8859-1" # ISO Latin 1
enc[9]="ISO8859-2" # ISO Latin 2
enc[30]="MacRoman" # Mac OS Roman
enc[12]="CP1252" # Windows Latin 1
enc[3]="EUCJIS" # Japanese (EUC)
enc[8]="SJIS" # Japanese (Shift JIS)
enc[1]="ASCII" # ASCII
rm -rf "$4"/csharp-compiled
mkdir "$4"/csharp-compiled
#mcs is the Mono CSharp Compiler
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
#echo -out:"$4"/csharp-compiled/"$classname".exe "$1"
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
#echo "$4"/csharp-compiled/
currentDir="$PWD"
cd "$4"/csharp-compiled/
files=`ls -1 *.exe`
status=$?
if [ $status -ne 0 ]
then
exit 1
fi
cd "$currentDir"
for file in $files
do
mv -f "$4"/csharp-compiled/$file "$file"
done
# Otherwise output the name of the input file without extension (this should be the same as the class name)
file="$1"
length=${#file}
first=`expr $length - 3`
classname=`echo "$file" | cut -c 1-"$first"`
echo $classname".exe"
exit 0
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1"
dmcs puts some messages on stdout, and some on stderr. CodeRunner expects stdout to only contain the output file name, nothing else, so to make that happen, >&2 can be used to redirect everything else to stderr.
dmcs -out:"$4"/csharp-compiled/"$classname".exe "$1" >&2
This worked for me on Sierra with current Mono and CodeRunner versions:
Language compile script:
file=$CR_FILENAME
/Library/Frameworks/Mono.framework/Versions/Current/bin/mcs "$CR_FILENAME" >&2
status=$?
if [ $status -ne 0 ]
then
exit $status
fi
echo $file | sed -e "s/\.cs/.exe/"
exit 0
Run command:
PATH="/Library/Frameworks/Mono.framework/Versions/Current/bin:$PATH"; mono $compiler
In MS compiler thre is a way to hide warnings
Pragma Warning Preprocessor Directive
#pragma warning disable 219
var test = "";
#pragma warning restore 219
It might help you.