I've been trying to fiddle around with Scriptcs and since I don't always want to fire up Visual Studio and use the interactive window, I'd tried my hand with Visual Studio code.
These are the steps I've taken:
#powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/scriptcs-contrib/svm/master/install/installer.ps1'))" && SET PATH=%HOME%\.svm\bin\;%HOME%\.svm\shims\;%PATH%
svm install 0.15.0
VS Code -> ext install scriptcsRunner -> Restart VS Code
Using a command prompt and issuing scriptcs [enter] Console.WriteLine("foo"); [enter] returns foo.
Using sublime Text 3, I get the same results. However, in Visual Studio code executing it with Ctrl + Shift + R gives me an empty Output window. How can I debug and rectify this?
Related
so i was trying to run a really basic C# program on vscode, here's the code:
using System;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
string Name;
Console.Write("Input your username:\n");
Console.Write("u/");
Name = Console.ReadLine();
Console.Write("\nSo your username is u/" + Name);
}
}
}
And naturally, it outputs:
Input your username:
u/
Except that i can't type anything next to the "u/", not even below.
it doesn't even freeze, popup an error or something like that, it just shows nothing.
and the same problem happens with C and C++. any tip?
Solutions
This problem is solved in two steps:
Adding Developer Command Prompt to Visual Studio Code
Updating "console" field in the launch.json file.
1. Adding Developer Command Prompt to Visual Studio Code
If you create C# programs with the terminal or powershell that comes with Visual Studio Code, you will be using the old toolkit. In this case, launch.json and tasks.json files aren't created in the .vscode directory when you compile the project, and you cannot use the new features of the C# programming language through the old toolset (only C# 5.0 is supported). To add a new terminal to Visual Studio Code, use the Control Shift P shortcut and enter the command "Terminal: Select Default Profile". Click on the settings icon of any default terminal on the window that opens and name the new terminal profile "Developer Command Prompt".
To check that the operation was successful, use the Control Shift P shortcut to view the new terminal listed and enter the command "Terminal: Select Default Profile".
Use the Control Shift P shortcut and enter the "Preferences: Open Setting (JSON)" command to open the setting.json file. You can view the newly added terminal information named "Developer Command Prompt" under "terminal.integrated.profiles.windows" settings. Update this field below:
"Developer Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\Tools\\VsDevCmd.bat",
],
"icon": "terminal-cmd"
}
Open "Developer Command Prompt" and create new project:
> mkdir TestProject
> cd TestProject
> dotnet new console
To receive data input from the console while debugging, change the configuration in the launch.json file as follows:
"console": "integratedTerminal"
When you press the F5 button to debug the opened project, a panel will open to select the environment. Select ".NET 5+ and .NET Core" from this field. In this step, the .vscode directory (launch.json and task.json files) will be created.
Accept all suggestions by following the prompts at the bottom right of Visual Studio Code as the new toolset will be used for the first time on the system. At this stage, launch.json and task.json files will be created under the .vscode directory.
2. Updating "console" Field In The launch.json
To receive data input from the console while debugging, change the configuration in the launch.json file as follows:
"console": "integratedTerminal"
3. Debugging On Test Project
Press F5 to debug the project:
References
Visual Studio Code - Terminal Profiles
OmniSharp - Instructions For Setting Up The .NET Core Debugger
Set As Default The Developer Command Prompt Of VS In VS Code
Debug Console Window Cannot Accept Console.ReadLine() Input During Debugging
When I'm compiling project via PowerShell:
PS C:\Windows\Microsoft.NET\Framework64\v4.0.30319> .\MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
then it fails
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets(2015,5): error MSB3091:
ask failed because "AxImp.exe" was not found, or the correct Microsoft Windows SDK is not installed. The task is looking for "AxImp.exe" in the "bin" subdirectory beneath the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v8.0A\WinSDK-NetFx40Tools-x86. You may be able to solve the problem by doing one of the following: 1) Install the Microsoft Windows SDK. 2) Install Visual Studio 2010. 3) Manually set the above registry key to the correct location. 4) Pass the correct location into the "ToolPath" parameter of the task."
but when I do it via VS Developer Command Prompt for VS2019
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.4.3
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
C:\Windows\System32>MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
then it works perfectly fine!
But, as you see Current Path (folder of MS Build) is quite different, so I tried executing this in PowerShell once again with VS Dev CMD's location:
PS C:\Windows\System32> cd "C:\Windows\System32"
PS C:\Windows\System32> MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj"
MSBuild.exe : The term 'MSBuild.exe' is not recognized as the name of a cmdlet, function, script file, or operable prog
ram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ MSBuild.exe "C:\Users\Me\repo\Proj\App.csproj" ...
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (MSBuild.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Windows\System32>
What's going on? Why I can compile my projects perfectly fine from Developer CMD meanwhile I cannot do it with Power Shell and it screams that I do not have Windows SDK?
Or which MS Build (apparently there's a few of them) should I use?
I found that using MSBuild from:
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
works fine, so apparently VS Dev CMD is using different MSBuild than the one that lies in C:\Windows\Microsoft.NET\Framework64\v4.0.30319
Case solved (for me)
I'm a super-beginner coder and trying to follow a training video on C# in Visual Studio 2015. The tutorial has me do a new Visual C# project as a Console Application. When I run my code using Ctrl+F5, it launches my code in the console as expected, but the Output --> Show output from build window is completely empty.
I've scoured this site and others for a solution. These are my current VS2015 settings, I've tried changing these with no success:
Show Output window when build starts is CHECKED
Redirect all Output Window text to the Immediate Window is UNchecked.
This is the code, verbatim what is shown in the tutorial:
using System;
namespace Hello
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World");
}
}
}
When the same code is run in the tutorial, the resulting output appears immediately in the Output window:
1>------ Build started: Project: Hello, Configuration: Debug Any CPU ------
1> Hello -> c:\users\[name]\documents\visual studio 2015\Projects\Hello\Hello\bin\Debug\Hello.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
I can see my Output window and I expect to receive this, but I get nothing. First time using Visual Studio, what am I missing?
Prior to adding Console.Read(); at the end of my code, running the code would launch the console with the following output:
Hello, World
Press any key to continue...
But, the build output window in VS remained blank as originally described.
After adding Console.Read();, the output in console no longer contained
Press any key to continue...
However, the build output in VS now displays what is expected as described in Original Post.
If I then remove Console.Read();, reverting back to my original code, the console output is back to original, and the VS build output window still gives expected output...
I suspect that, using Visual Studio for the first time, it had never been directed to write to the Output window, which was accomplished here with Console.Read(); and should do this going forward...
Link to solution I used:
https://stackoverflow.com/a/5301276/11953574
I'm trying to learn some C# and am currently using the internal console for outputs, but when it comes to keyboard inputs, I've read that it can not be done in the internal console on VS 2017 for Mac.
So I try to do it on external console, but all I get is this :
bash -c 'clear; cd "/Users/gb/Projects/reTest/reTest/bin/Debug";
"/Library/Frameworks/Mono.framework/Versions/5.8.1/bin/mono32"
--debug --debugger-agent=transport=dt_socket,address=127.0.0.1:56795 "/Users/gb/Projects/reTest/reTest/bin/Debug/reTest.exe" ; echo $? >
/var/folders/s_/sljf42_d01bdxlb5s_rwgsj80000gn/T/tmp563f24ea.tmp;
echo; read -p "Press any key to continue..." -n1; exit'; exit
I guess the console tries to execute a .exe application which is not possible in this case !
It's a console project by the way... I haven't found any solution for that so far.
Thks.
After further researches I found out that my bash was kind of corrupted somehow so I modified the .bash_profile file which had some extra inconvenient text..
I just installed Visual Studio Community 2017 on my mac, created a console C# project and trying to run the hello world string, but it keeps on opening the mac console when running the script, and moreover, it looks like it crashes somehow
bash -c 'clear; cd "/Users/gb/C#_Projects/TestProject/TestProject/bin/Debug"; "/Library/Frameworks/Mono.framework/Versions/5.8.0/bin/mono32" --debug --debugger-agent=transport=dt_socket,address=127.0.0.1:51188 "/Users/gb/C#_Projects/TestProject/TestProject/bin/Debug/TestProject.exe" ; echo $? > /var/folders/s_/sljf42_d01bdxlb5s_rwgsj80000gn/T/tmp231b1334.tmp; echo; read -p "Press any key to continue..." -n1; exit'; exit
macbook-pro-de-gb:~ gb$ bash -c 'clear; cd "/Users/gb/C#_Projects/TestProject/TestProject/bin/Debug"; "/Library/Frameworks/Mono.framework/Versions/5.8.0/bin/mono32" --debug --debugger-agent=transport=dt_socket,address=127.0.0.1:51188 "/Users/gb/C#_Projects/TestProject/TestProject/bin/Debug/TestProject.exe" ; echo $? > /var/folders/s_/sljf42_d01bdxlb5s_rwgsj80000gn/T/tmp231b1334.tmp; echo; read -p "Press any key to continue..." -n1; exit'; exit
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
I tried to change the configuration in the build option by unchecking "Build with external console" but each time I build this is checked again...
To prevent the external Mac console form opening, you have to right click your project (not the solution) and click "Options". Under the Run option, click on "Default". Uncheck the box "Run on external console". In my case I had to restart visual studio to have that working.
If you don't see the "Hello" output, go to View->Pads->Application Output, then you can pin that, or dock it.
But if you need to insert text, such as with Console.ReadLine(), you'll have to use the external console anyway.