Compiling C# code without access to Visual Studio

I’m not a developer and as such I don’t have a copy of Visual Studio but this evening I needed to compile somebody else’s C# code to produce a dynamic link library (DLL) and call it from a Windows PowerShell script. Somewhere back in my distant past I recall using Turbo Pascal, Borland C++, early versions of Visual Basic and even Modula-2 to make/link/compile executables but I’ve never used a modern compiled language (even on Linux I avoid rolling my own code and opt for RPM-based installations). So I downloaded and installed Visual C# 2005 Express Edition (plus service pack 1, plus hotfix to make it run on Windows Vista).

Sadly that didn’t get me anywhere – I’m totally confused in the Visual Studio IDE and anyway, the instructions I had told me to access the Visual Studio command prompt and run csc /t:library filename.cs.

It turns out that the Visual Studio Express Editions don’t include the Visual Studio command prompt but in any case, the C# compiler (csc.exe) is not part of Visual Studio but comes with the Microsoft.NET framework (on my system it is available at %systemroot%\Microsoft.NET\Framework\v2.0.50727\). Once I discovered the whereabouts of the compiler, compiling the code was a straightforward operation.

As for what I did with the DLL and PowerShell, I’ll save that for another post.

Comments

4 responses to “Compiling C# code without access to Visual Studio”

  1. […] to impersonate the COM security on the required object (I initially had some trouble with this but everything was fine once I located the compiler). I placed the resulting VSWrapperForPSH.dll file in […]

  2. Outsourcing avatar

    I tell you thing for sure…even developers like me don’t know how to compile from the command line. Microsoft provides such a good IDE (Visual Studio) you never have to do it.

    Anyway you should have used Visual C# Express by opening the .sln file and click Build. The .sln file is the project file.

  3. Mark Wilson avatar

    Thanks for that tip – I can see that the VS IDE is powerful… but it takes some time to learn – your advice is really appreciated :-)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.