« Visual studio code » : différence entre les versions
De Banane Atomic
Aller à la navigationAller à la recherche
Ligne 380 : | Ligne 380 : | ||
Visual studio code is a code editor redefined, available on Windows, Linux and OS X, optimized for building web and cloud applications. | Visual studio code is a code editor redefined, available on Windows, Linux and OS X, optimized for building web and cloud applications. | ||
<kode lang=bash> | <kode lang=bash> | ||
# Visual Studio Code open source distribution: code-oss | |||
pacman -S code | |||
# Microsoft's Visual Studio Code distribution | |||
yay visual-studio-code-bin | |||
</kode> | </kode> | ||
[https://github.com/microsoft/vscode/wiki/Differences-between-the-repository-and-Visual-Studio-Code Differences between the repository and Visual Studio Code] | |||
== Extension C# == | == Extension C# == |
Version du 28 mars 2020 à 20:56
Liens
- Visual Studio Code Documentation
- Building dotnet with clang 4.0 and associated issues
- dotnet AUR
- .NET Core Roadmap
Raccourcis clavier
Ctrl + Shift + P | Lancer une commande |
Ctrl + Shift + I | Formater le code |
Ctrl + ! | Afficher le terminal |
Utilisation
# créé le template "Console Application" (vscode.csproj Program.cs) dotnet new console # lister les templates disponibles dotnet new -l # lancer VS code dans le répertoire courant code . |
À l'ouverture de vscode, les éléments manquants sont téléchargés automatiquement (OmniSharp, .NET Core Debugger) |
Settings
File → Preferences → Settings Ctrl + ,
Règlage | |
---|---|
Side Bar à droite | Side Bar: Location = right |
Formatter à la sauvegarde | Editor: Format On Save Editor: Format On Paste |
OLD
"editor.fontSize": 16, "editor.fontFamily": "'Inconsolata-g', 'Droid Sans Mono', 'Courier New', monospace, 'Droid Sans Fallback'", "editor.wordWrap": "on", "editor.cursorBlinking": "phase", "editor.dragAndDrop": false, "editor.minimap.enabled": true, "files.autoSave": "afterDelay", "files.autoSaveDelay": 3000, "window.zoomLevel": 1, // masque la section OPEN EDITORS "explorer.openEditors.visible": 0, "explorer.enableDragAndDrop": false, // Git Bash (défaut: powershell ) "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe", |
NuGet Package Manager
Installer un paquet:
- Ctrl + P
- >
- Nuget Package Manager:Add Package
- Entrer le nom du paquet à installer
Extensions
Dernier élément du menu de gauche ou View → Extensions
- ~/.vscode/extensions
- %USERPROFILE%\.vscode\extensions
C#
Nom de l'extension | Description |
---|---|
C# Extensions |
|
NuGet Package Manager | installation de références avec NuGet |
.NET Core Test Explorer | tests unitaires |
C# XML Documentation Comments | commentaires avec /// |
ILSpy .NET Decompiler | décompiler des assemby - Ctrl+Shift+P → ilspy |
Angular
Nom de l'extension | Description |
---|---|
Angular v6 Snippets | |
AngularDoc for Visual Studio Code | arborescence pour navigation dans le code |
Auto Import | import auto dans les fichier TS |
ESLint | vérification du code javascript |
markdownlint | lint for MD |
Markdown All in One | format MD document + racourcis-clavier |
TSLint | vérification du code ts. Rules Config ClientApp\tslint.json |
TypeScript Hero |
|
Move TS | Move TypeScript files and update relative imports |
Auto Close Tag | HTML / XML |
Auto Rename Tag | renomme la balise fermante en même temps que la balise ouvrante |
Communes
Nom de l'extension | Description |
---|---|
vscode-icons | belles icônes dans l'arborescence de fichiers |
Azure Repos |
|
Git History | affiche l'historique des commits |
phpfmt | format code PHP avec Ctrl + Shift + I Alt + Shift + F. Ne fonctionne pas avec les fichiers hybrides PHP/HTML. |
Create GUID | génère un GUID et le copie dans le presse-papier |
Travailler avec plusieurs projets (multi-root workspaces)
- Ouvrir un second dossier dans le même VScode: File → Add Folder to Workspace (lien)
- Référencer un autre projet:
cd MainProject dotnet add reference ../LibProject/LibProject.csproj |
MainProject.csproj |
<ItemGroup> <ProjectReference Include="..\LibProject\LibProject.csproj" /> </ItemGroup> |
Debug multiple projects
- Ajouter compounds au fichier .vscode/launch.json du workspace.
- Dans Debug l'entrée définit dans compounds est disponible.
.vscode/launch.json |
{ "version": "0.2.0", "configurations": [ { "name": "BlazorServerApp", "type": "coreclr", "request": "launch", "preLaunchTask": "build BlazorServerApp", "program": "${workspaceFolder}/BlazorServerApp/bin/Debug/netcoreapp3.1/BlazorServerApp.dll", "args": [], "cwd": "${workspaceFolder}/BlazorServerApp", "stopAtEntry": false, "serverReadyAction": { "action": "openExternally", "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } }, { "name": "WebApi", "type": "coreclr", "request": "launch", "preLaunchTask": "build WebApi", "program": "${workspaceFolder}/WebApi/bin/Debug/netcoreapp3.1/WebApi.dll", "args": [], "cwd": "${workspaceFolder}/WebApi", "stopAtEntry": false, "serverReadyAction": { "action": "openExternally", "pattern": "^\\s*Now listening on:\\s+(https?://\\S+)" }, "env": { "ASPNETCORE_ENVIRONMENT": "Development" }, "sourceFileMap": { "/Views": "${workspaceFolder}/Views" } } ], "compounds": [ { "name": "BlazorServerApp / WebApi", "configurations": [ "BlazorServerApp", "WebApi" ], "preLaunchTask": "build all" } ] } |
Tasks
Lister les build tasks: Ctrl + Shift + B ou Terminal → Run Build Task |
.vscode/tasks.json |
{ "version": "2.0.0", "tasks": [ { "label": "build", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/WebApi.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, { "label": "publish", "command": "dotnet", "type": "process", "args": [ "publish", "${workspaceFolder}/WebApi.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" }, { "label": "watch", "command": "dotnet", "type": "process", "args": [ "watch", "run", "${workspaceFolder}/WebApi.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "problemMatcher": "$msCompile" } ] } |
Appeler d'autres taches
.vscode/tasks.json |
{ "version": "2.0.0", "tasks": [ { "label": "build all", "dependsOn": [ "build server", "build client" ], "group": "build", "problemMatcher": [] }, { "label": "build server", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Server/Server.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "group": "build", "problemMatcher": "$msCompile" }, { "label": "build client", "command": "dotnet", "type": "process", "args": [ "build", "${workspaceFolder}/Client/Client.csproj", "/property:GenerateFullPaths=true", "/consoleloggerparameters:NoSummary" ], "group": "build", "problemMatcher": "$msCompile" } ] } |
launch settings
Quand l’application est lancée avec dotnet run, launchSettings.json est lu s’il est disponible:
- le premier profil avec "commandName": "Project" est utilisé
- les paramètres environmentVariables remplacent les variables d’environnement
launchSettings.json |
{ "profiles": { "MyApp": { "commandName": "Project", "launchBrowser": true, "applicationUrl": "http://localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } } |
SQL Server
- installer l'extension mssql
- nouvelle page → en bas à droite clique sur Plain Text → choisir SQL
- ou ouvrir un fichier *.sql
- F1 → MS SQL: Connect ou cliquer sur Disconnected en bas à droite → Create Connection Profile
- Ctrl + Shift + E exécuter du code
Erreurs
Visual Studio Code is unable to watch for file changes in this large workspace
# Afficher le nombre max de fichiers qui peuvent être surveillés cat /proc/sys/fs/inotify/max_user_watches # Modifier temporairement le nombre max de fichiers qui peuvent être surveillés echo 65536 > /proc/sys/fs/inotify/max_user_watches # Modifier le nombre max de fichiers qui peuvent être surveillés (Archlinux) echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system |
Microsoft.Common.props was not found
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "/usr/lib/mono/xbuild/15.0/Microsoft.Common.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. /opt/dotnet/sdk/2.1.105/Sdks/Microsoft.NET.Sdk/Sdk/Sdk.props
Installer MSBuild
yaourt msbuild # aur/msbuild-15-bin 15.5_xamarinxplat.2017.08.16.12.03_0xamarin3_ubuntu1404b1-3 msbuild /ver |
The terminfo database is invalid
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild. System.InvalidOperationException: The terminfo database is invalid.
TERM=xterm dotnet build TERM=xterm dotnet run echo $TERM # xterm-256color |
Installation
Visual studio code is a code editor redefined, available on Windows, Linux and OS X, optimized for building web and cloud applications.
# Visual Studio Code open source distribution: code-oss pacman -S code # Microsoft's Visual Studio Code distribution yay visual-studio-code-bin |
Differences between the repository and Visual Studio Code
Extension C#
Installer l'extension C#:
- Bouton extension: dernier bouton du menu latéral de gauche
- Rechercher C#
# installer .NET core sdk pour compiler des applications et ses dépendances yaourt dotnet-sdk-2.0 |
OBSOLÈTE - Installing the .NET Core Debugger on Arch Linux
File → Preferences → Settings
{ "csharp.fallbackDebuggerLinuxRuntimeId": "ubuntu.16.10-x64" } |
# erreur Debug adapter process has terminated unexpectedly yaourt icu57 |