How do I get started using Cygwin for C# development? - c#

I'm coming from Linux, and I want to try to learn some C# development.
But I'm partial to the command line and using Vim. Is it easy to set up Cygwin to run the csc compiler from the command line and to edit C# files directly in the console with Vim?
I downloaded SharpDevelop, but I would really like to give console-style C# development a try.
Specifically, how do I set up the PATH (is there an equivalent to .bash_profile?) so that I can run csc and vim from the Windows Console?
I'm running Windows 7.

You should give VsVim a try. With C#, you'll thank yourself for sticking with Visual Studio.

Specifically, how do I set up the PATH (is there an equivalent to .bash_profile?) so that I can run csc and vim from the Windows Console?
Exactly like in linux. The only difference, IIRC, is that you use .bashrc instead of .bash_profile. Edit (or create) the file in your cygwin user's home directory (~/) and write the usual export PATH=$PATH:/path/to/other/bin lines.
http://www.cygwin.com/cygwin-ug-net/setup-env.html

I love VsVim, as suggested by Joel. But you said you want to try without Visual Studio, so here:
vim integrates well with gnu make, and writing makefiles for C# programs is quite simple.
Just be careful about tabs vs spaces, same as on Linux (and like I'm not doing on SO, since getting tabs in HTML code blocks is hard). You'll just need a rule along the lines of:
myapp.exe : mymain.cs myhelpers.cs mydialog.cs
csc.exe /o /out:$# $^
Then from inside vim, you can just use the :make command.

ProcessStartInfo pInfo = new ProcessStartInfo("C:\\Cygwin\\bin\\mintty.exe");
pInfo.Arguments = "-i /Cygwin-Terminal.ico -";
if cygwin is installed on C:\

Related

Compiling an executable file using Notepad++ and Csscript

I am very new to C# and am wanting to write my code using a text editor like Notepad++ and compile using csscript. I have the two working and I am getting results from my code.
However, so far, I have only been able to run my code as interpreted, but I will eventually want to compile exe or dll files.
Am I able to compile my code into a standalone exe or dll using notepad++ and csscript, please?
Just an update for your original question...
CS-Script plugin for Notepad++ actually allows building normal executables that can be executed as any other managed exe.
Little too late, but here's the one that worked for me: I called this batch script bnr.bat (Build and Run)
echo Building project..
C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /out:"%1\%2.exe" %3
echo Running project
%1\%2.exe
pause
Save this bnr.bat file and and then use NPP's Run and set The Program to Run as follows and before you press Run button, press Save and provide your custom shortcut keys:
<directory_where_you_saved_bnr.bat>\bnr.bat $(CURRENT_DIRECTORY) $(NAME_PART) $(FULL_CURRENT_PATH)
the $ constants are defined internally in NPP:
$(CURRENT_DIRECTORY) is the full path of the directory containing your C# file.
$(NAME_PART) is the name of your C# file minus extension (.cs).
$(FULL_CURRENT_PATH) is the full path for your C# file.
This does not have any error checking, but pause in batch script will allow you to see the errors and exceptions within the console before you exit the script.
I had set the PATH environment variabile, but somehow this batch script did not find csc.exe, because it was looking at the npp bin directory.
For .NET 5+ (and .NET Core), you can compile your project using the .NET Command Line Interface (CLI)
The command
dotnet publish
creates the files you need to run your program.
No, you will need a compiler (Microsoft´s from VS or Mono)
csc.exe is what you need. It should be at C:\Windows\Microsoft.NET\Framework\v4.0.30319.
Here is a link to a reference. http://msdn.microsoft.com/en-us/library/2fdbz5xd.aspx
And check out Visual Studio express, it makes life easier.
Thanks for the reply.
I have Visual studio but the license expires in 7-days.
I am using Notepad++ with an add-in called cs-script. The add-in checks and runs code in a similar manner to Visual studio but it will not compile an exe or dll file.
However, to answer my own question and as suggested by quarksoup, the answer lies within the csc comiler. By using the /flags, I am able to compile my programs from the command-line. I shall write a batch file that will do the work for me.
Regards

Monodevelop 4.0 no codeview

I'm developing an application (http://sourceforge.net/projects/audiocuesheet/) and use fedora. Since the rpm for fedora is from monodevelop 2.8.x and I need the features of monodevelop 4.0. I downloaded the tarball and build monodevelop. It works good as described, but I can not view the source of my sourcefiles (screenshot).
Has anyone any idea, why this fails? I tried starting monodevelop with no redirection, but couldn't find any error.
It's a known bug.
The only solution (as for now) is to change your GTK theme in KDE settings -> Application Appearance.
They say (the bug has been filed somewhere) it's the problem with the theme itself, but I find it hard to believe... I guess you have oxygen-gtk set, change it to, for example, Raleigh, it will work.
Remember to restart monodevelop ;-)
I like oxygen theme, I find it the most annoying issue with md-4.0..
Edit:
http://mono.1490590.n4.nabble.com/Text-editor-problem-with-monodevelop-4-0-td4658742.html - here is where I've found the solution.
This might by an issue with the oxygen-gtk-theme. See here. Start Monodevelop with the environment variable OXYGEN_DISABLE_INNER_SHADOWS_HACK set to 1.
In the shell:
export OXYGEN_DISABLE_INNER_SHADOWS_HACK=1
monodevelop
You can also put this as a shell script to /usr/local/bin/monodevelop. Then monodevelop is automatically started with this environment variable.
#!/bin/sh
export OXYGEN_DISABLE_INNER_SHADOWS_HACK=1
/usr/bin/monodevelop
Remember to make it executable with sudo chmod a+x /usr/local/bin/monodevelop

Using Vim as a C# editor, facing a few issues

I have a few questions and a few issues using vim as a C# editing environment. Firstly I am new to vim, so it all is a bit of a learning process for me, I would appreciate any advice and guidance you may have to offer. Secondly I am having some issues getting any cs file to compile.
I am using this as my cs.vim compiler:
if exists("current_compiler")
finish
endif
let current_compiler = "cs"
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
CompilerSet errorformat&
CompilerSet errorformat+=%f(%l\\,%v):\ %t%*[^:]:\ %m,
\%trror%*[^:]:\ %m,
\%tarning%*[^:]:\ %m
execute 'CompilerSet makeprg=' . cs#get_net_compiler("csc.exe") . "\\ %
Not sure exactly where I found this. But if I am in a directory with spaces in the dir name I get an error that the file cannot be found to compile. I think I need to tell it to escape the spaces, but how do I do this?
even if I switch back to the original cs.vim compiler file, i get weird issues and it does not appear to compile:
above and beyond that is it possible to work with C# projects in vim and when you compile have it recognize references etc?
EDIT: for clarification, I have and use Visual Studios as my main IDE. I would like to learn to use vim better, so thus I ask these questions.
Thanks!
Personally, I use a combination of Vim and Visual Studio (with VsVim installed) for my day to day C# coding. I do the longer spurts of editing with pure Vim because VsVim, as nice as it is, just isn't the same as the full Vim environment with its ecosystem. Nothing beats Visual Studio for interactive debugging.
To get the compiler, I use the following settings in my vimrc, stolen and transmogrified from some section of the internet:
set errorformat=\ %#%f(%l\\\,%c):\ %m
set makeprg=C:\\windows\\microsoft.net\\framework\\v4.0.30319\\msbuild.exe\ /nologo\ /v:q\ /property:GenerateFullPaths=true
Please note that this integrates MSBuild and so works with the full .sln file--the whole build just works, no need to muck around with individual files. All you have to do to perform a full build is run :make.
While not strictly required, I also like this flag:
set shellcmdflag=\/C
because it ensures that the cmd window closes on its own.

How can I programmatically build my solution files from C# code?

I have a large solution containing many projects with one of them being a Setup project. There are also many current versions stored in separate branches. I have a build tool that used to work in .NET 2, but hasn't worked since we upgraded to .NET 4.
Internally, the new .NET 4 version of the build tool uses Microsoft.TeamFoundation.Client.RegisteredTfsConnections.GetProjectCollections() and versionControlServer.GetAllTeamProjects(false) to get a collection of TeamProjects from my TFS source control server.
I then display them visually in the UI and when a user clicks on a particular solution version, the application calls the following to get the latest for that solution version:
workspace.Get(new string[] { serverPath }, VersionSpec.Latest, RecursionType.Full,
GetOptions.GetAll);
The application used to build the solution files and this would include the Setup project. At this stage, the setup project would create an MSI that the application could be installed with. It is this last step that I am having problems with.
I need to be able to programmatically build the solution that the user selected using C# code. The working .NET 2 code for this was as follows:
Process process = new Process();
ProcessStartInfo processStartInfo = process.StartInfo;
processStartInfo.FileName = processName;
processStartInfo.Arguments = string.Format(" \"{0}\" /BUILD \"Release|Any CPU\"",
solutionPath);
processStartInfo.WorkingDirectory = processDirectory;
process.Start();
There is no error when this is run, but it no longer launches Visual Studio and builds the code. Clearly, this was a poor way to do it initially, but I can't find the 'correct' way using the TFS classes.
I also tried running MSBuild.exe directly (similar to the above example), and this does build the solution, but for some reason does not build the Setup project that produces the MSI. Note that I do NOT use any manually created build files.
Unfortunately, useful documentation for the Microsoft.TeamFoundation namespace is hard to find! I'm hoping that someone here has made use of these classes and can direct me to a solution to this problem.
If at all possible, I need to use .NET classes (eg. not Process.Start) as I really need to know when the build has finished as well. I can however set up a FileSystemWatcher object for this if this is asking too much.
msbuild skips the installer projects because it doesn't know how to build them. FinalBuilder shells out to devenv.exe to build these.
Calling `devenv /build "Release|Any CPU" /project "MyInstaller.vdproj" should run the build you need from the command line, without starting the VS GUI. Try it!
With all that said: We, too, use FinalBuilder, and VS Installer is deprecated, so you'll probably want to plan on replacing that.
It turns out that the problem was unfortunately completely unrelated. The .NET 2 code that was to be updated had hard coded 'Program Files' into the devenv.exe file path - however the new computers are 64bit and Visual Studio 2010 is installed into 'Program Files (x86)'!
So this means that the above code sample DOES work and WILL allow me to build the solutions from C#. It's not the object oriented way that I would have preferred to do it, but after all your comments, I'm just glad to have got it working at all.
Thanks for your time everyone.

Compiling C# with csc.exe from within Notepad++ using NPPExec script

I'm having trouble writing a NPPExec script (for Notepad++) to compile C# source using Microsoft's csc.exe. I had no problem getting MinGW up and running for my c++ stuff, but the same script structure doesn't seem to work for C#. Does anybody have a working C# NPPExec script?
Three quick notes:
While my mingw installed to a path with no spaces (\MinGW\bin), it appears that my C# compiler is buried in \Program Files\, a path with multiple spaces. Does this matter?
I was able to compile using the Microsoft SDK-installed command prompt (which I think sets some environment variables), so I know the compiler works.
In the NPPExec option box, I have selected FOLLOW $(CURRENT_DIRECTORY). Does this matter?
Thanks.
Here is my nppexec script for C# (.NET 3.5) to compile the currently opened file and run:
"c:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe" /out:"$(FULL_CURRENT_PATH).exe" "$(FULL_CURRENT_PATH)"
"$(FULL_CURRENT_PATH).exe"
In the "Plugins -> NppExec" menu:
Select "Save all files on execute"
Select "Follow $(CURRENT_DIRECTORY)".
Answers for your questions:
1) Use double quotes (") for full path of csc like my configuration.
2) At least for .NET 3.5, only full path to csc is enough, no need to load VS environment variables.
3) It is better to select "FOLLOW $(CURRENT_DIRECTORY)" so that the compiled EXE is under the same directory.

Categories