Compiling C# Code with Coderunner — No Warnings Allowed - c#

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.

Related

Long path in powershell and .net

We're executing following commands
...
[System.IO.File]::WriteAllBytes($pathA, $data)
[System.IO.Compression.ZipFile]::ExtractToDirectory($pathA, $pathB)
// OR
Expand-Archive $pathA -DestinationPath $pathB
on Windows 10 Ent. x64 in versions
Name Value
---- -----
PSVersion 5.1.17763.316
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17763.316
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
The code works unless $pathB happens to be too long. Tried many suggestions found here
\\?\$pathB does work in Explorer but in this code fails in ExtractToDirectory with
The filename, directory name, or volume label syntax is incorrect
and in Expand-Archive with
Cannot process argument because the value of argument "drive" is null.
It shouldn't be a matter of backslash escaping, if I doubled them it gave me
Illegal characters in path
Also tried New-PSDrive as in
New-PSDrive -Name "X" -PSProvider FileSystem -Root $pathBase
but I'm getting
A drive with the name 'X' does not exist.
I read that it needs -Persist, which gives me
...the root must be a file system location on a remote computer.
Tried
net use x: $pathBase
// OR
subst $pathBase "x:\"
Join-Path -Path "x:\" -ChildPath ...
and both end in
Cannot find drive. A drive with the name 'x' does not exist.
Are any of these used wrong? If not - what else to try to fix this?
Thank you

Extracting directory / file names in a Makefile

Could someone help me understand the behaviour of the makefile, below? To give some context, I am trying to generated a series of c# classes from a set of .proto files. The proto files are contained within a directory structure which i want to mirror in the output. So, assuming my source files are in a folder called 'Source' and I am outputting into a folder called 'Generated', if a file resides in:
'Source/Foo/Bar/myfile.protoc'
then output should be:
'Generated/Foo/Bar/MyFile.cs'.
This seems simple enough however I am seeing some strange behaviour when using dir/notdir in the make file. here is an example:
# Makefile to build message definitions within this repo
PROTOS:= SourceFiles/Module_1/BasicMessage.proto SourceFiles/Module_2/BasicMessage.proto
withVariables:
for proto in $(PROTOS) ; do \
echo $(dir $$proto) ; \
echo $(notdir $$proto) ; \
done;
hardCoded:
echo $(dir ./SourceFiles/Module_1/BasicMessage.proto)
echo $(notdir ./SourceFiles/Module_1/BasicMessage.proto)
echo $(dir ./SourceFiles/Module_2/BasicMessage.proto)
echo $(notdir ./SourceFiles/Module_2/BasicMessage.proto)
Essentially, when I have the collection of file names in a variable and try to iterate them, dir/notdir does not seem to recognised the separators in the path. Running Make hardCoded here gives:
./SourceFiles/Module_1/
BasicMessage.proto
./SourceFiles/Module_2/
BasicMessage.proto
which is what i would expect. However, running withVariables gives:
./
SourceFiles/Module_1/BasicMessage.proto
./
SourceFiles/Module_2/BasicMessage.proto
I am still pretty new to make files, so I am probably missing something simple, but if anyone can explain why these two examples behave differently, it would be greatly appreciated.
The recipes are expanded by make before being passed to the shell. So, in the recipe of withVariables, the $(dir $$proto) and $(notdir $$proto) are expanded to ./ and $proto, respectively. The recipe becomes:
for proto in SourceFiles/Module_1/BasicMessage.proto SourceFiles/Module_2/BasicMessage.proto; do \
echo ./ ; \
echo $proto ; \
done;
which logically produces the output you see. You cannot use make functions in your recipes and expect them to be executed by the shell. Instead you can invoke the standard dirname and basename external programs from your recipe:
withVariables:
for proto in $(PROTOS); do \
echo $$(dirname $$proto); \
echo $$(basename $$proto); \
done
The recipe is expanded by make as:
for proto in SourceFiles/Module_1/BasicMessage.proto SourceFiles/Module_2/BasicMessage.proto; do \
echo $(dirname $proto); \
echo $(basename $proto); \
done
which, when executed by the shell, outputs:
host> make withVariables
SourceFiles/Module_1
BasicMessage.proto
SourceFiles/Module_2
BasicMessage.proto

bash process started from C# returns unexpected characters

I started bash (cygwin) from C# and I for that purpose created a new process from C:\\cygwin64\\bin\\bash.exe with the arguments --login -i. I've also redirected its output.
Bash runs, but the output contains unexpected characters like [0m[37;1m or [0m> or [K> or even > (there is an ESC character before all of these but stackoverflow does not seem to let it be displayed). This is unexpected cause I don't seem to see any of these characters from the mintty program.
Why is this happening? Where are these characters coming from? How can I prevent them from appearing?
The unexpected characters are escape sequences used to format text output (concerning the terminal emulator). (See Wikipedia: terminal emulator for more about this.)
In detail, the output of prompt may be configured using certain bash variables, namely PS1, PS2, PS3, PS4. In How to change bash prompt color based on exit code of last command?, the effect of modifying them (just for fun) is shown.
In your case, the call of bash should source a special script which re-defines them simply without any escape sequence. Thus, you could get rid of the undesired formatting. This may help: SO: Running a custom profile file on remote host but this seems also promising: Is it possible to start a bash shell with a profile at a custom location, in a one liner command?.
Writing this, I remembered that certain commands (e.g. ls) support colored output also. As I was not sure I tried this:
$ mkdir test ; cd test ; touch test1 ; ln -s test1 test2 ; mkdir test3 ; touch test4 ; chmod a+x test4
$ ls --color
test1 test2 test3 test4
$
I do not know how to format it with colors here but, on my xterm, it's looking like Mardi Gras. Thus, I use hexdump to show the effect:
$ ls --color | hexdump -c
0000000 t e s t 1 \n 033 [ 0 m 033 [ 0 1 ; 3
0000010 6 m t e s t 2 033 [ 0 m \n 033 [ 0 1
0000020 ; 3 4 m t e s t 3 033 [ 0 m \n 033 [
0000030 0 1 ; 3 2 m t e s t 4 033 [ 0 m \n
0000040
As you can see: ls does use terminal escape sequences also. Then I remembered the variable TERM. This link The TERM variable mentions the terminfo or termcap also which are probably part of the game.
Thus, in addition to the re-definition of PS1 ... PS4, it could be useful to redefine TERM also:
$ TERM=
$ ls --color | hexdump -c
0000000 t e s t 1 \n t e s t 2 \n t e s t
0000010 3 \n t e s t 4 \n
0000018
$
Btw. I recognized that the bash prompt is still colored. Thinking twice this becomes obvious: The escape sequences in PS1 ... PS4 are "hard-coded" i.e. does not consider the setting of TERM.
Update:
To test this I wrote a sample script mybashrc:
PS1="> "
PS2=">>"
PS3=
PS4="++ "
TERM=
and tested it with bash in cygwin on Windows 10 (64 bit):
$ bash --init-file mybashrc -i
> echo "$PS1 $PS2 $PS3 $PS4"
> >> ++
> exit
exit
$
Btw. I noticed that the [Backspace] key works somehow strange in my sample session: It still has the intended effect but the output is wrong. Output is instead of deleting the last character although the internal buffer seems to handle this correctly:
$ bash --init-file mybashrc -i
> echo "Ha ello"
Hello
> echo "Ha ello" | hexdump -c
0000000 H e l l o \n
0000006
> exit
exit
$
(In both cases, I typed [Backspace] once after echo "Ha.) The reason is possibly the missing terminal emulation.
Thus, I believe if the console (in your application) handles backspaces in the output channel of the bash appropriately then it should be less confusing.

Mono-Service2 - Init.d script not working

I have created the init.d script below for my C# windows service to be executed on an Amazon Linux EC2 Instance. I hope Amazon linux is based on fedora linux.
I have below init.d script and I googled and found the script.
but if I start the service using the following command:
sudo service amaziersysd start
I am getting below error message:
cat: /tmp/amaziersysd.lock: No such file or directory
Pls note : I am newbie in setting up mono, and I am running mono 3.2.3 built from source.
#!/bin/sh
daemon_name=amaziersysd
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 0
fi
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/mono/mono-service2
NAME=amaziersysd
DESC=amaziersysd
MONOSERVER=$(which mono-service2)
MONOSERVER_PID=$(cat /tmp/amaziersysd.lock)
case "$1" in
start)
stat_busy "Starting amaziersysd"
if [ -z "${MONOSERVER_PID}" ]; then
${MONOSERVER} -l:/tmp/amaziersysd.lock /etc/amazierlb/sysdaemon/Amazier.CollectSysStat.exe
stat_done
else
echo "amaziersysd is already running!"
stat_fail
fi
;;
stop)
stat_busy "Stopping amaziersysd"
if [ -n "${MONOSERVER_PID}" ]; then
kill ${MONOSERVER_PID}
rm /tmp/amaziersysd.lock
stat_done
else
echo "amaziersysd is not running"
stat_fail
fi
;;
restart)
$0 stop
sleep 1
$0 start
stat_done
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0

How to run Doxygen Makefile?

I have created a .NET C# project that I have commented using blocks similar to ///<summary>A summary...</summary> that I would like to document using Doxygen. I have set up Doxygen and it runs generating a some 100 .tex-files and a Makefile.
As I have understood, the Makefile is the key to generating the documentation as a PDF, however I do not get it to work.
I'm using a Mac to do the LaTeX and Doxygen bit by writing make -f Makefile in the Terminal when I am in the Doxygen LaTeX output directory.
all: refman.pdf
pdf: refman.pdf
refman.pdf: clean refman.tex
pdflatex refman
makeindex refman.idx
pdflatex refman
latex_count=5 ; \
while egrep -s 'Rerun (LaTeX|to get cross-references right)' refman.log && [ $$latex_count -gt 0 ] ;\
do \
echo "Rerunning latex...." ;\
pdflatex refman ;\
latex_count=`expr $$latex_count - 1` ;\
done
clean:
rm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf
When running, i get the following message:
MacBook-Pro-13:latex sehlstrom$ make
rm -f *.ps *.dvi *.aux *.toc *.idx *.ind *.ilg *.log *.out *.brf *.blg *.bbl refman.pdf
make: *** No rule to make target `refman.tex', needed by `refman.pdf'. Stop.
How can I get the Makefil thing work?
refman.tex is supposed to be created by Doxygen. I just tested with my installed version, doxygen 1.7.2, and it created a refman.tex.
Make sure you aren't setting any option that says this is a component of a larger project that shouldn't have its own index.

Categories