C#: Visual studio code compile time - c#

I have a C# (.net core v2.1) solution that built from some of projects. Compile it takes ~90 seconds. This is my tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [ "${workspaceFolder}\\my.sln"],
"isBuildCommand": true,
"showOutput": "silent",
"problemMatcher": "$msCompile"
}
]
}
This is my lunch.json:
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": "Test",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/Tests/Test/bin/Debug/netcoreapp2.1/Test.dll",
"args": [],
"cwd": "${workspaceFolder}/Tests/Test/",
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
]
}
I notice that every time I build the project OR run the current configuration - it compile all the project agian - agian, 90 seconds of waiting.
In previous days, I did it with Visual Studio (the old and good) much more faster - it wasn't compile all the projects UNLESS they changed.
Is this possible to do it with Visual Studio Code?

Related

Why is my program not debugging on vscode (c#) like it used to? I am being asked to attach to a process

[Disclaimer: very new to coding]
I am learning to code and have so far covered some basic tutorials and can produce simple programs. These all used to run fine.
For some reason I can't explain, I am now running into an error every time I am trying to "start debugging".
For example, when trying to debug the default "Hello World!" code (as below),
using System;
namespace specialitySelector
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
A drop down list appears (as below) and the program does not run! I have no idea why this is doing this :/.
Image of drop down list that appears and what I see
In my launch.json file I have this:
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net5.0/specialitySelector.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "externalTerminal",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
What am I doing wrong and how do I fix this? I have even tried uninstalling and re-installing vscode with no result.
Thanks.

Visual Studio Code: How to configure 'dotnet' not to show warnings when compiling

OK. I am in .NET Core and using Visual Studio Code on a Mac machine. Now, whenever I run my C# project then Visual Studio Code shows this annoying message:
The preLaunch task 'build' terminated with exit code 1
It shows me the option to click on a button called "Show problems". When I click on this button, it only shows the warning messages.
Now, if it was errors then it's OK to see this message. But the fact that it shows this message every time there are warnings (which to me is OK). That is very annoying. Is there a way I can configure Visual Studio Code to not show these messages on things like warnings?
In order to disable warnings, you should add -nowarn to args in the tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyProject.csproj",
"-nowarn" // here
],
"problemMatcher": "$msCompile"
}
]
}
It might be a problem with your task.json file. Check the arguments of the file and make sure the build is pointing at the right location:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/MyProject.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

ASP.NET core web API json configuration not copied to debug folder

I am working on an ASPNET core web API application. When I try to debug the application, the "appsetting.json" file is not copied to the debug folder. At this moment I am copying this file whenever I made changes. If I did not copy the file and I just run the dotnet run command, the application fails to load giving the file not found exception.
Should I do anything in the Launch.json file?
Here is what I have in mine.
I have also tried adding
"/appsettings.json":"${workspaceFolder}/appsettings.json"
in the "sourceFileMap" property in this JSON file but no use.
Please help.
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"webRoot": "${workspaceFolder}"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/SmartAPI/bin/Debug/netcoreapp2.0/smartAPI.dll",
"args": [
],
"cwd": "${workspaceFolder}/SmartAPI",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"requireExactSource": false,
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
]
}
Right click on the file in object explorer, click on properties and change the value of "Copy to output directory". This is do not copy by default when you create the project but can be changed.
Update
Didn't realise you were using VS Code - this answer might help you: https://stackoverflow.com/a/44378406/8532748

Simple dotnetcore app not running in VS Code

I tried to follow the instructions here: https://learn.microsoft.com/en-us/aspnet/core/tutorials/web-api-vsc
I did:
mkdir todoapi
cd todoapi
dotnet new webapi
When I opened Startup.cs in VS Code, I didn't get any warn message asking me the following:
Select Yes to the Warn message "Required assets to build and debug are missing from 'TodoApi'. Add them?"
Select Restore to the Info message "There are unresolved dependencies".
What is wrong with my local setup?
I just want to run this program from withi VS code.
If I run in debug mode I get this error:
The preLaunchTask 'build' terminated with exit code 1.
In the powershell terminal the command 'dotnet' doesn't work either. Should it?
Update
I re-started VS COde and now it picks up the command in terminal:
dotnet
Now when I run I get this:
launch: launch.json must be configured. Change 'program' to the path
to the executable file that you would like to debug.
My launch.json has:
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
},
Try:
dotnet restore //restore dependencies
dotnet build //build project
dotnet run //run project

VS code Debugger cant the Program C# on Ubuntu OS

I'm new to Visual Studio Code, i installed it on my Ubuntu Machine and installed the debugger.
i can run my program normally by using the "donnet run" command.
i configured the the debugger by adding the:`"csharp.fallbackDebuggerLinuxRuntimeId": "ubuntu.16.10-x64"
to the settings.json file, and chenged the launch.json to point to my dll like this
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/Code.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
and now on i get this on my screen
Any ideas?
I Found The problem and fixed it it was a syntax issue
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp1.1/Code.dll>",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"console": "internalConsole"
}
THe ">" at the end of this line is the problem' its a leftover from the original code

Categories

Resources