I am developing a c# Excel DLL addin in VS Code Ver 1.42.1. I quickly got an initial C#-only test version working using the VS code editor with only manual Command Line (CL) compiler commands below:
csc -t:library -debug -out:Eandin.dll -r:system.dll[....more...] Eaddin.cs
csc -t:exe -debug -r:Eaddin.dll -r:system.dll[...more...] Test_Eadin.cs
I am able to successfully manually CL compile this with above commands and then run. But I now need the debugger to debug, test, and validate my app and code. In VS Code, I have created numerous variation of tasks.json and launch.json to automate my manual commands. My *.json files work to build and launch (^shiftB & F5) in VS code. The code runs and produces output, but the debugger does not work.
I think my problem is not sufficiently understanding dotnet c# compilation. Or what?
Can someone please provide guidance on how to accomplish this?
Thank you.
Related
When I am using python in Visual Studio Code, I have the run button at the top right, however, when I am in a c# file, the run button is not there.
Why is that, and how can I fix it?
Since VS Code is a tool built with C# in mind, having the Run hidden is not a disadvantage but rather to dedicate a complete UI for Running and Debugging your C# code. The Run and Debug UI which you can access from the left menu gives your this capability with comprehensive tools to help you debug.
Activating this tool to run correctly involves two setups, one-time setup and a per-project setup (Don't let this intimidate you, it is just a click of a button)
First Time Setup
1. Install .NET command line tools
Install the .NET Core command line tools (CLI) by following the installation part of the instructions here: https://dotnet.microsoft.com/download
2. Install C# Extension for VS Code
In the extensions tab, enter C# in the search box and press Enter. Select the extension from Microsoft and click on Install. If you have previously installed the C# extension, make sure that you have a recent version.
3. Wait for download of platform-specific files
The first time that C# code is opened in VS Code, the extension will download the platform-specific files needed for debugging and editing. Debugging and editor features will not work until these steps finish.
Once Per Project
1. Get a project
You can start from scratch by creating an empty console project with dotnet new. Begin by opening the terminal in Visual Studio Code (View->Integrated Terminal) or CTRL+` and type these commands:
cd ~
mkdir MyApplication
cd MyApplication
dotnet new console
2. Open the directory in VS Code
Go to File->Open Folder (File->Open on macOS) and open the directory in Visual Studio Code. If this is the first time that the C# extension has been activated, it will now download additional platform-specific dependencies.
3. Add VS Code configuration files to the workspace
VS Code needs to be configured so it understands how to build your project and debug it. For this there are two files which need to be added -- .vscode/tasks.json and .vscode/launch.json.
Tasks.json is used to configure what command line command is executed to build your project, and launch.json configures the type of debugger you want to use, and what program should be run under that debugger.
Launch.json configures VS Code to run the build task from tasks.json so that your program is automatically up-to-date each time you go to debug it.
If you open the folder containing your project, the C# extension can automatically generate these files for you if you have a basic project. When you open a project and the C# extension is installed, you should see the following prompt in VS Code:
Clicking Yes when you see this prompt is all that you really have to do when you open a new dotnet project. If the files are there already you won't be prompted.
Clicking Yes on this prompt should add these resources. Should you need to add those resources manually please check the reference link below.
4. Start debugging
Your project is now all set. Set a breakpoint or two where you want to stop, click the debugger play button (or press F5) and you are off.
Reference Link: https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger.md
try pressing f5, should do the same thing as the run button
I tried running simple code in my vscode. initially got of "scripts not found internally or externally" after installing the scripts from "choclately" and installing "sriptcsRunner" extension.
I'm again facing a problem running my code.
For VisualStudio Code all you really need to run is the C# extension.
To create a new project you open the integrated terminal in VS Code inside your workspace and run
dotnet new console
That will create everything you need.
You might need to run .NET Generate Assets for Build and Debug, you can do so by pressing ctrl + shift + P and enter the above command there, it should pretty much autocomplete.
to debug your program you can run by pressing F5
To execute normally use this:
dotnet run
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
Visual Studio shows the exact command line use to compiler and link a C++ project under Project Properties -> C/C++ -> Command Line and Linker ->Command Line, but, I was not able to find similar property page for C# projects.
Does any know what's the best way to find out the csc.exe command line arguments used to compile a C# project
Instead of using csc.exe directly, I would recommend looking at msbuild instead. With msbuild, you just have to run msbuild yourProject.csproj to compile it.
Also, per this MSDN blog, the csc.exe command line you see in the output window isn't really being used.
In Visual Studio, go to Debug->Windows->Output. When you compile your project this window will show you the commands it is using to compile your code, including the CSC command(s).
Be sure chose the "Show output from: Build" in the option dropdown in the Output window.
See MSDN: Command-line Building With csc.exe
In Visual Studio 2010 go to
Tools->Options->Project and Solutions->Build and Run
change "MSBuild project build output verbosity" to something less filtering than Minimal (for example "Normal"). There will be a lot more talk in the Build Output window after this and you should be able to see the actual command line of how CSC was invoked.
I have installed Visual Studio 2008 on our build machine because we want to build the setup project to create MSI installer for our C# application.
From IDE, it works fine. The installer is created as expected.
Switch to command line, with the follow command the process finished without any error but there is no output (no installer created)
DevEnv.exe .\\SystemSoftwareInstaller\\SystemSoftwareInstaller.vdproj /build Debug /Out "debugErr.txt"
change the /build to /deploy to /rebuild have no difference (no installer created)
I am doing anything wrong?
I just fought with a similar issue, where I'd run the devenv.exe and get no feedback and no output, even with the /Log flag. This is the exact same call I'd use in 2005, and it worked like a charm. But then I found a devenv.com in the same folder, so I tried that, and it ran as expected. I don't know the difference between the .com and .exe versions, but you might try that.
I think the problem is that you are running DevEnv.exe and not DevEnv.com.
This should output to the console.
DevEnv .\\SystemSoftwareInstaller\\SystemSoftwareInstaller.vdproj /build Debug /Out "debugErr.txt"
Try building the solution file instead of the vdproj file in your command line statement
There must be at least one project in the solution that form the output of the installer project. These will need to be built as well.
Interesting question. I thought this would be pretty easy as well. I was able to easily do a release build by opening a VS2008 command prompt in the folder with my vdproj and running:
devenv SomeName.vdproj /build
But release was a lot trickier. After a few failed attempts on my own, this guy showed the way. For some reason, the fully qualified path to the sln and the vdproj seemed to do the trick (again I was in a VS2008 command prompt but this time I was in the SLN folder):
devenv "C:\SomePath\SomeSlnName.sln"
/rebuild Debug /project
"C:\SomePath\ProjectFolder\SomeProjectName.vdproj"
/projectconfig Debug
It doesn't make sense to create an installer for the Debug build, you always want the Release build.
If that's really necessary then open the .vdproj in Visual Studio, Build + Configuration Manager and tick the Build checkbox for the Debug configuration. Beware that this property is stored in the .sln file, not the .vdproj file so click File + Save All to let VS write the solution file.