3

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:

  1. 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?

  2. 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.

  3. In the NPPExec option box, I have selected FOLLOW $(CURRENT_DIRECTORY). Does this matter?

Thanks.

1 Answer 1

18

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Sorry, don't have enough reputation to vote up yet. Will come back when I do.
You're a Godsend. You won't believe how many sources I've gone through online to get this question answered before finally stumbling upon yours. Thank you.
Note that if you want to use a more up-to-date compiler, run nuget install Microsoft.Net.Compilers -OutputDirectory "C:\wherever", then reference the csc.exe in the OutputDirectory you specified instead of the one above. Visit here for more info: github.com/dotnet/roslyn

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.