Run C# Console Application on Visual Studio Code Editor on Windows - visual-studio-code

Is there any way to create (from scratch) and run simple C# Console app in VSCode editor. ?
Can you please provide step-by-step instruction how I can do that?
What kind of files I must to include (except HelloWolrd.cs obviously)?
What kind of commands I must to execute?

Navigate to the folder you want to create the console app in. In VSCode, use Ctrl+` to open the terminal window or go to View and select Integrated Terminal. Now type the following below:
dotnet new console
dotnet restore
dotnet run

The best way at this present time to create a console application is to create a DNX style Console Application.
I would advise that you download and install the generator-aspnet Yeoman generator and use that to generate a DNX Console application. Once you've got generator-aspnet installed, in your terminal/console app type yo aspnet and select Console Application.
Here's a thorough guide to creating a DNX Console application which will work with VS Code: http://docs.asp.net/en/latest/dnx/console.html

I was trying to get a 'hello world' set up using visual studio code and c# on mac/osx.
the way I did it was as follows:
Install VS Code and the C# extension
Here (https://www.microsoft.com/net/core#macos) are instructions for installing dotnet core using brew:
Install OpenSSL
brew update
brew install openssl
ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/
ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/
Install dotnet core pkg: https://go.microsoft.com/fwlink/?LinkID=827526
Create a folder somewhere and in that folder run dotnet new
Go into VS code and open the folder to get the project loaded
Open the terminal in that folder and run dotnet run
To create run as a task
CMD+shift+P then type task
select the Task: Configure Task Runner option
in the tasks.json file after the build task, add the following:
{
"taskName":"run",
"args": [
"${workspaceRoot}/project.json"
]
}

Related

dotnet-ef does not exist - Windows 10 WSL (Ubuntu)

I've been testing dotnet core 3 in different OS like Windows and Linux(Ubuntu). All of them are working fine with EF Core!
However, I decided to give a chance to Windows WSL - Windows Subsystem for Linux and see how it works. That's why I'm here!
The problem with WSL and Ubuntu 18.04 is:
I installed EF Core globally and restarted the terminal. * Up to this point, the EF version is 3.1.4
> dotnet tool install --global dotnet-ef
I get the following error when I try to run any dotnet ef command:
> dotnet ef database update
Could not execute because the specified command or file was not found.
Possible reasons for this include:
* You misspelled a built-in dotnet command.
* You intended to execute a .NET Core program, but dotnet-ef does not exist.
* You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
Has anyone faced the same error using Windows WSL and Ubuntu 18.04?
Finally I found the solution!
I've tried to export the PATH variable export PATH="$PATH:$HOME/.dotnet/tools" as #kapsiR mentioned. However, it was valid for a single terminal session only. So if I close the terminal and open again, the $PATH configuration disappears.
The solution that works for me:
cd /home/yourUserName
Edit the file .zshrc and add this line export PATH="$PATH:$HOME/.dotnet/tools/". NOTE: I'm using zsh shell in this case. You should change it if you are using a different one.
Restart your terminal
Sadly, the PATH isn't exported directly after the installation of the dotnet-sdk.
You basically have two options:
Add the tool path manually for the current session:
export PATH="$PATH:$HOME/.dotnet/tools"
OR
Start a new session of the WSL
With the dotnet-sdk there comes a script which adds it to the PATH, it's located under /etc/profile.d/dotnet-cli-tools-bin-path.sh.

Visual Studio Code only compiles when launched from project folder on Linux

I have Visual Studio Code installed in Ubuntu 20.04. I love how it works. I installed it from the tar ball. Same with the SDK. I just found that those appear to work better than installing from deb packages.
I created a desktop file so I could add Visual Studio Code to the dock and launch it that way, but what I've noticed is that projects won't compile. I get errors stating it can't find the project even though the errors are listing the folder where the items exist.
The only way I can get it to work is to:
Open a terminal.
Navigate to the folder where the project files reside.
Launch code from the command line.
Then it works. Otherwise, I get a pop-up error that says "The preLaunchTask 'build' terminated with exit code -2" and then the terminal window is filled with errors.
Here's the last of the error messages and then I opened up a terminal and it shows that I'm in the folder for the project and the csproj exists there:
This also happens if I install Visual Studio code from a repository. It seems launching it from the Unity desktop breaks something. But if I launch it from the command line in a terminal session from the folder where the project resides, then the problem goes away.
I can also reproduce this error from the command line if I launch Visual Studio Code from a different folder than the project I'm trying to compile.
Is this common? Just curious. I'm wondering if because when I launch it from the Unity desktop, it's launching under a different
I got it working under 20.04. I must have done something wrong so I did a wipe of the .NET Core install and reinstalled it all using the bash shell script and then was able to install Code via Software Installer tool. Not sure why it didn't work before, but it works now.

How to handle an .fsproj file on the command line?

I would like to use exercism to solve F# exercises. I do this on Fedora.
Exercism downloads an .fsproj file. How can I handle it from the command line?
Is there something like the command make for a Makefile?
If you have the dotnet SDK installed.
dotnet build X.fsproj should restore and build the project.
dotnet run X.fsproj will run it. You can also run it against a .sln file.
dotnet test X.fsproj will execute your unit tests. Note: Here it reported I only had 1 test file (wrong) but picked up all my tests.
To test if you have it installed and on your PATH, execute: dotnet --version. The current version is 3.1.
dotnet --help will show you all possible commands.
Of interest may be that F# Interactive is now baked into the SDK.
dotnet fsi to enter interactive environment.
#quit;; to exit interactive environment.
This allows you to play with F# right in the command line.

Launch .NET Core project in VS Code using dotnet run

We have a .net core 2.0 project that we've been using in Visual Studio. I want to switch to using VS Code. I updated the launchsettings.json to include a Project launch profile (instead of IIS) and made the necessary changes to be able to use the dotnet cli to run it.
However, when I try to launch it in VS Code I don't see where the dotnet run is being used because I want to use that command to run the project since we need to pass a configuration to that command in order for it to work. The command line looks like this:
dotnet run -c Dev --launch-profile Project
I don't know how to set up vs code to launch using the above command.

Could not install typings files... in VS Code, with Bash on Ubuntu on Windows

I'm trying to use Visual Studio Code with Bash on Ubuntu on Windows. I have VS Code installed on Windows, but otherwise use Bash exclusively for my JavaScript development workflow.
I have node and npm installed on Bash (via apt-get), however, I do not have node and npm also on Windows to avoid duplication. In my VS Code settings, I have configured the integrated shell to use Bash:
"terminal.integrated.shell.windows": "C:\\windows\\Sysnative\\bash.exe"
The integrated shell works fine, and node and npm are both accessible. However, when I launch VS Code on my project, I get the warning:
Could not install typings files for JavaScript langauge features. Please ensure that NPM is installed or configure 'typescript.npm' in your user settings
I have tried both the following settings, neither of which work:
"typescript.npm": "C:\\windows\\Sysnative\\bash.exe"
"typescript.npm": "C:\\windows\\Sysnative\\bash.exe -c \"npm\""
Is it possible to get VS Code to install typings files via the npm that is installed on Bash?
Try setting “externalTerminal.windowsExec”: “bash” in your settings file to set it as the terminal executable and then restart VS Code